iOS 전면 광고
Last updated
Last updated
self.interstitialAd = [[AdropInterstitialAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"];
self.interstitialAd.delegate = self;
[self.interstitialAd load];
...
// 광고를 표시해야 할 경우 show 함수를 호출하세요.
[self.interstitialAd showFromRootViewController:self];
let interstitialAd = AdropInterstitialAd(unitId: "PUBLIC_TEST_UNIT_ID_INTERSTITIAL")
interstitialAd.delegate = self
interstitialAd.load()
...
// 광고를 표시해야 할 경우 show 함수를 호출하세요.
interstitialAd.show()
class AdropInterstitialAdWrapper: AdropInterstitialAdDelegate {
var interstitialAd: AdropInterstitialAd?
var errorHandler: (String) -> Void
init(_ unitId: String, handler: @escaping (_ error: String) -> Void) {
self.interstitialAd = AdropInterstitialAd(unitId: unitId)
self.errorHandler = handler
interstitialAd?.delegate = self
}
func onAdReceived(_ ad: AdropAds.AdropInterstitialAd) {
print("onAdReceived")
}
func onAdFailedToReceive(_ ad: AdropAds.AdropInterstitialAd, _ error: AdropAds.AdropErrorCode) {
print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
self.errorHandler(AdropErrorCodeToString(code: error))
}
func load() {
interstitialAd?.delegate = self
interstitialAd?.load()
}
func show(fromRootViewController: UIViewController) {
interstitialAd?.show(fromRootViewController: fromRootViewController)
}
}
struct InterstitialAdView: View {
@State var adropInterstitialAdWrapper :AdropInterstitialAdWrapper? = nil
var body: some View {
NavigationView {
VStack {
Button {
adropInterstitialAdWrapper = AdropInterstitialAdWrapper("PUBLIC_TEST_UNIT_ID_INTERSTITIAL") { _ in }
adropInterstitialAdWrapper?.load()
} label: {
Text("load")
}
.padding(.all)
Button {
adropInterstitialAdWrapper?.show(fromRootViewController: (UIApplication.shared.windows.first?.rootViewController)!)
} label: {
Text("show")
}
.padding(.all)
Spacer()
}
.navigationTitle("InterstitialAd Example")
}
}
}