Display popup ad on Apple
Display an popup ad
let popupAd = AdropPopupAd(unitId: "PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM")
popupAd.delegate = self
popupAd.backgroundColor = your_color // optional UIColor
popupAd.hideForTodayTextColor = your_color // optional UIColor
popupAd.closeTextColor = your_color // optional UIColor
popupAd.delegate = self
popupAd.load()
...
// call show function when the ad needs to be displayed.
popupAd.show(fromRootViewController: viewController)
self.popupAd = [[AdropPopupAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM"];
self.popupAd.delegate = self;
self.popupAd.backgroundColor = your_color; // optional UIColor
self.popupAd.hideForTodayTextColor = your_color; // optional UIColor
self.popupAd.closeTextColor = your_color; // optional UIColor
[self.popupAd load];
...
// call show function when the ad needs to be displayed.
[self.popupAd showFromRootViewController:self];
class AdropPopupAdWrapper: AdropPopupAdDelegate {
var popupAd: AdropPopupAd?
var errorHandler: (String) -> Void
init(_ unitId: String, handler: @escaping (_ error: String) -> Void) {
self.popupAd = AdropPopupAd(unitId: unitId)
self.errorHandler = handler
self.popupAd.backgroundColor = your_color; // optional UIColor
self.popupAd.hideForTodayTextColor = your_color; // optional UIColor
self.popupAd.closeTextColor = your_color; // optional UIColor
popupAd?.delegate = self
}
func onAdReceived(_ ad: AdropAds.AdropPopupAd) {
print("onAdReceived")
}
func onAdFailedToReceive(_ ad: AdropAds.AdropPopupAd, _ error: AdropAds.AdropErrorCode) {
print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
self.errorHandler(AdropErrorCodeToString(code: error))
}
func load() {
popupAd?.delegate = self
popupAd?.load()
}
func show(fromRootViewController: UIViewController) {
popupAd?.show(fromRootViewController: fromRootViewController)
}
}
struct AdropPopupAdView: View {
@State var popupAdWrapper :AdropPopupAdWrapper? = nil
var body: some View {
NavigationView {
VStack {
Button {
popupAdWrapper = AdropPopupAdWrapper("PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM") { _ in }
popupAdWrapper?.load()
} label: {
Text("load")
}
.padding(.all)
Button {
popupAdWrapper?.show(fromRootViewController: (UIApplication.shared.windows.first?.rootViewController)!)
} label: {
Text("show")
}
.padding(.all)
Spacer()
}
.navigationTitle("PopupAd Example")
}
}
}
Last updated