Skip to main content

Overview

Popup ads are ad formats that appear on screen at specific moments. They can be displayed at desired timings such as app launch, content load completion, or specific event occurrences. Users can close them by tapping the close button or selecting “Don’t show for today.”

Features

  • Popup format displayed at center or bottom of screen
  • Supports both image and video ads
  • Provides close, dim (background) click, and “Don’t show for today” options
  • Customizable background color, text color, etc.
  • Non-intrusive yet effective ad experience
Use test unit IDs in development environment. See the Test Unit IDs section.

Implementation Steps

Implement popup ads in 4 steps:
  1. Initialize - Create AdropPopupAd instance
  2. Set Delegates - Set delegates to receive ad and close events
  3. Load Ad - Request and receive ad
  4. Show Ad - Display ad on screen

UIKit Implementation

Basic Implementation

import AdropAds

class ViewController: UIViewController {
    private var popupAd: AdropPopupAd?

    override func viewDidLoad() {
        super.viewDidLoad()
        loadPopupAd()
    }

    // 1. Initialize and load ad
    private func loadPopupAd() {
        popupAd = AdropPopupAd(unitId: "YOUR_POPUP_UNIT_ID")
        popupAd?.delegate = self
        popupAd?.closeDelegate = self
        popupAd?.load()
    }

    // 2. Show ad
    private func showPopupAd() {
        guard let popupAd = popupAd,
              popupAd.isLoaded else { return }
        popupAd.show(fromRootViewController: self)
    }
}

Delegate Implementation

// Ad delegate implementation
extension ViewController: AdropPopupAdDelegate {
    // Ad received successfully (required)
    func onAdReceived(_ ad: AdropPopupAd) {
        print("Popup ad received")
        // Show ad when ready
        showPopupAd()
    }

    // Ad receive failed (required)
    func onAdFailedToReceive(_ ad: AdropPopupAd, _ errorCode: AdropErrorCode) {
        print("Popup ad failed to receive: \(errorCode)")
    }

    // Ad impression (optional)
    func onAdImpression(_ ad: AdropPopupAd) {
        print("Popup ad impression")
    }

    // Ad clicked (optional)
    func onAdClicked(_ ad: AdropPopupAd) {
        print("Popup ad clicked")
    }

    // Before showing popup ad (optional)
    func onAdWillPresentFullScreen(_ ad: AdropPopupAd) {
        print("About to show popup ad")
    }

    // After showing popup ad (optional)
    func onAdDidPresentFullScreen(_ ad: AdropPopupAd) {
        print("Popup ad shown")
    }

    // Before dismissing popup ad (optional)
    func onAdWillDismissFullScreen(_ ad: AdropPopupAd) {
        print("About to dismiss popup ad")
    }

    // After dismissing popup ad (optional)
    func onAdDidDismissFullScreen(_ ad: AdropPopupAd) {
        print("Popup ad dismissed")
        // Preload next ad
        loadPopupAd()
    }

    // Popup ad show failed (optional)
    func onAdFailedToShowFullScreen(_ ad: AdropPopupAd, _ errorCode: AdropErrorCode) {
        print("Popup ad failed to show: \(errorCode)")
    }
}

// Close delegate implementation
extension ViewController: AdropPopupAdCloseDelegate {
    // Close button clicked (optional)
    func onClosed(_ ad: AdropPopupAd) {
        print("Popup ad close button clicked")
    }

    // Dim (background) clicked (optional)
    func onDimClicked(_ ad: AdropPopupAd) {
        print("Popup ad dim area clicked")
    }

    // "Don't show for today" clicked (optional)
    func onTodayOffClicked(_ ad: AdropPopupAd) {
        print("Don't show for today selected")
        // Save today's date to control next display
        UserDefaults.standard.set(Date(), forKey: "lastPopupAdHiddenDate")
    }
}

SwiftUI Implementation

In SwiftUI, use UIViewControllerRepresentable or get the rootViewController from UIWindow to display.

ViewModel Pattern

import SwiftUI
import AdropAds

// ViewModel
class PopupAdViewModel: ObservableObject {
    @Published var isAdReady = false
    @Published var isAdShowing = false

    private var popupAd: AdropPopupAd?

    init() {
        loadAd()
    }

    func loadAd() {
        popupAd = AdropPopupAd(unitId: "YOUR_POPUP_UNIT_ID")
        popupAd?.delegate = self
        popupAd?.closeDelegate = self
        popupAd?.load()
    }

    func showAd() {
        guard let popupAd = popupAd,
              let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
              let rootViewController = windowScene.windows.first?.rootViewController else {
            return
        }

        popupAd.show(fromRootViewController: rootViewController)
    }

    func canShowTodayOffAd() -> Bool {
        guard let lastHiddenDate = UserDefaults.standard.object(forKey: "lastPopupAdHiddenDate") as? Date else {
            return true
        }

        return !Calendar.current.isDateInToday(lastHiddenDate)
    }
}

// Ad delegate
extension PopupAdViewModel: AdropPopupAdDelegate {
    func onAdReceived(_ ad: AdropPopupAd) {
        DispatchQueue.main.async {
            self.isAdReady = true
        }
    }

    func onAdFailedToReceive(_ ad: AdropPopupAd, _ errorCode: AdropErrorCode) {
        print("Ad receive failed: \(errorCode)")
    }

    func onAdDidPresentFullScreen(_ ad: AdropPopupAd) {
        DispatchQueue.main.async {
            self.isAdShowing = true
        }
    }

    func onAdDidDismissFullScreen(_ ad: AdropPopupAd) {
        DispatchQueue.main.async {
            self.isAdShowing = false
            self.isAdReady = false
        }
        // Preload next ad
        loadAd()
    }
}

// Close delegate
extension PopupAdViewModel: AdropPopupAdCloseDelegate {
    func onClosed(_ ad: AdropPopupAd) {
        print("Popup ad closed")
    }

    func onDimClicked(_ ad: AdropPopupAd) {
        print("Popup ad dim clicked")
    }

    func onTodayOffClicked(_ ad: AdropPopupAd) {
        print("Don't show for today")
        UserDefaults.standard.set(Date(), forKey: "lastPopupAdHiddenDate")
    }
}

// View
struct ContentView: View {
    @StateObject private var adViewModel = PopupAdViewModel()

    var body: some View {
        VStack {
            Text("Popup Ad Example")
                .font(.title)

            Button("Show Popup Ad") {
                if adViewModel.canShowTodayOffAd() {
                    adViewModel.showAd()
                } else {
                    print("Already selected 'Don't show for today'")
                }
            }
            .disabled(!adViewModel.isAdReady)
            .padding()
        }
        .onAppear {
            // Auto show on app start
            if adViewModel.isAdReady && adViewModel.canShowTodayOffAd() {
                adViewModel.showAd()
            }
        }
    }
}

Customization

You can customize the appearance of popup ads.

Set Background Color and Text Color

private func loadPopupAd() {
    popupAd = AdropPopupAd(unitId: "YOUR_POPUP_UNIT_ID")
    popupAd?.delegate = self
    popupAd?.closeDelegate = self

    // Set background color
    popupAd?.backgroundColor = UIColor.black.withAlphaComponent(0.8)

    // "Don't show for today" text color
    popupAd?.hideForTodayTextColor = UIColor.white

    // Close button text color
    popupAd?.closeTextColor = UIColor.white

    popupAd?.load()
}

Customization Options

PropertyTypeDescriptionDefault
backgroundColorUIColor?Popup background (dim) colorBlack (alpha 0.5)
hideForTodayTextColorUIColor?”Don’t show for today” text colorWhite
closeTextColorUIColor?Close button text colorWhite

Delegate Methods

AdropPopupAdDelegate (Ad Events)

Required Methods

onAdReceived
(AdropPopupAd) -> Void
Called when ad is received successfully. You can call show() at this point to display the ad.
onAdFailedToReceive
(AdropPopupAd, AdropErrorCode) -> Void
Called when ad fails to load. You can check the cause of failure through the error code.

Optional Methods

onAdImpression
(AdropPopupAd) -> Void
Called when ad impression is recorded.
onAdClicked
(AdropPopupAd) -> Void
Called when user clicks the ad.
onAdWillPresentFullScreen
(AdropPopupAd) -> Void
Called just before popup ad is displayed.
onAdDidPresentFullScreen
(AdropPopupAd) -> Void
Called immediately after popup ad is displayed on screen.
onAdWillDismissFullScreen
(AdropPopupAd) -> Void
Called just before popup ad is dismissed.
onAdDidDismissFullScreen
(AdropPopupAd) -> Void
Called immediately after popup ad is dismissed. Good time to preload the next ad.
onAdFailedToShowFullScreen
(AdropPopupAd, AdropErrorCode) -> Void
Called when ad fails to show. You can check the cause of failure through the error code.

AdropPopupAdCloseDelegate (Close Events)

All methods are optional.
onClosed
(AdropPopupAd) -> Void
Called when user clicks the close button.
onDimClicked
(AdropPopupAd) -> Void
Called when user clicks outside the popup (dim area).
onTodayOffClicked
(AdropPopupAd) -> Void
Called when user selects “Don’t show for today.” You can save the date in this callback to prevent showing ads for the rest of the day.

Implementing “Don’t Show for Today”

How to properly handle when users select “Don’t show for today.”

Implementation Using UserDefaults

class PopupAdManager {
    private let todayOffKey = "popupAd_todayOff_date"
    private var popupAd: AdropPopupAd?

    // Check if ad can be shown today
    func canShowAdToday() -> Bool {
        guard let lastHiddenDate = UserDefaults.standard.object(forKey: todayOffKey) as? Date else {
            return true // Can show if never hidden
        }

        // Check if saved date is today
        return !Calendar.current.isDateInToday(lastHiddenDate)
    }

    // Load and show ad
    func loadAndShowAd(from viewController: UIViewController) {
        guard canShowAdToday() else {
            print("Ad will not be shown today")
            return
        }

        popupAd = AdropPopupAd(unitId: "YOUR_POPUP_UNIT_ID")
        popupAd?.delegate = self
        popupAd?.closeDelegate = self
        popupAd?.load()
    }
}

extension PopupAdManager: AdropPopupAdDelegate {
    func onAdReceived(_ ad: AdropPopupAd) {
        // Auto show after receiving ad
        if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
           let rootViewController = windowScene.windows.first?.rootViewController {
            ad.show(fromRootViewController: rootViewController)
        }
    }

    func onAdFailedToReceive(_ ad: AdropPopupAd, _ errorCode: AdropErrorCode) {
        print("Ad receive failed: \(errorCode)")
    }
}

extension PopupAdManager: AdropPopupAdCloseDelegate {
    func onTodayOffClicked(_ ad: AdropPopupAd) {
        // Save today's date
        UserDefaults.standard.set(Date(), forKey: todayOffKey)
        print("Popup ad will not be shown for the rest of today")
    }
}

Best Practices

1. Appropriate Display Timing

Popup ads are effective when shown at these timings:
// ✅ Good: On app launch
func applicationDidFinishLaunching() {
    loadAndShowPopupAd()
}

// ✅ Good: After content load completes
func onContentLoaded() {
    if shouldShowPopupAd() {
        showPopupAd()
    }
}

// ✅ Good: After specific event completes
func onAchievementUnlocked() {
    showPopupAd()
}

// ❌ Bad: While user is working
func onUserTyping() {
    showPopupAd() // Disrupts user experience
}

2. Respect “Don’t Show for Today”

If user selects “Don’t show for today,” make sure to honor it.
func shouldShowPopupAd() -> Bool {
    // Check "Don't show for today"
    guard canShowAdToday() else {
        return false
    }

    // Check other conditions
    return true
}

3. Frequency Capping

Don’t show popup ads too frequently.
class PopupAdFrequencyManager {
    private let lastShownKey = "popupAd_lastShown"
    private let minimumInterval: TimeInterval = 3600 // 1 hour

    func canShowAd() -> Bool {
        // Check "Don't show for today"
        guard canShowAdToday() else {
            return false
        }

        // Check minimum time interval
        guard let lastShown = UserDefaults.standard.object(forKey: lastShownKey) as? Date else {
            return true
        }

        return Date().timeIntervalSince(lastShown) >= minimumInterval
    }

    func recordAdShown() {
        UserDefaults.standard.set(Date(), forKey: lastShownKey)
    }
}

Test Unit IDs

Use the following test unit IDs during development and testing.
Ad TypeTest Unit ID
Popup (Bottom Image)PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM
Popup (Center Image)PUBLIC_TEST_UNIT_ID_POPUP_CENTER
Popup Video (Bottom 16:9)PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM_VIDEO_16_9
Popup Video (Bottom 9:16)PUBLIC_TEST_UNIT_ID_POPUP_BOTTOM_VIDEO_9_16
Popup Video (Center 16:9)PUBLIC_TEST_UNIT_ID_POPUP_CENTER_VIDEO_16_9
Popup Video (Center 9:16)PUBLIC_TEST_UNIT_ID_POPUP_CENTER_VIDEO_9_16
Make sure to use actual unit IDs created in AdControl Console for production deployment.