Skip to main content

Overview

Interstitial ads are ads displayed in full-screen format covering the entire app screen. They are suitable for display at natural transition points in the app, such as game level transitions or content page changes.

Features

  • Immersive ads covering the entire screen
  • Maintained until user explicitly closes
  • Supports both image and video ads
  • High visual attention
Use test unit ID in development environment: PUBLIC_TEST_UNIT_ID_INTERSTITIAL

Implementation Steps

Implement interstitial ads in 4 steps:
  1. Initialize - Create AdropInterstitialAd instance
  2. Set Delegate - Set delegate to receive ad 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 interstitialAd: AdropInterstitialAd?

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

    // 1. Initialize and load ad
    private func loadInterstitialAd() {
        interstitialAd = AdropInterstitialAd(unitId: "YOUR_UNIT_ID")
        interstitialAd?.delegate = self
        interstitialAd?.load()
    }

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

isLoaded Property

Property to check if the ad is loaded. It’s recommended to check this value before calling show().
if interstitialAd?.isLoaded == true {
    interstitialAd?.show(fromRootViewController: self)
}

Delegate Implementation

extension ViewController: AdropInterstitialAdDelegate {
    // Ad received successfully (required)
    func onAdReceived(_ ad: AdropInterstitialAd) {
        print("Interstitial ad received")
        // Show ad when ready
        showInterstitialAd()
    }

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

    // Ad impression (optional)
    func onAdImpression(_ ad: AdropInterstitialAd) {
        print("Interstitial ad impression")
    }

    // Ad clicked (optional)
    func onAdClicked(_ ad: AdropInterstitialAd) {
        print("Interstitial ad clicked")
    }

    // Before showing full screen ad (optional)
    func onAdWillPresentFullScreen(_ ad: AdropInterstitialAd) {
        print("About to show interstitial ad")
    }

    // After showing full screen ad (optional)
    func onAdDidPresentFullScreen(_ ad: AdropInterstitialAd) {
        print("Interstitial ad shown")
    }

    // Before dismissing full screen ad (optional)
    func onAdWillDismissFullScreen(_ ad: AdropInterstitialAd) {
        print("About to dismiss interstitial ad")
    }

    // After dismissing full screen ad (optional)
    func onAdDidDismissFullScreen(_ ad: AdropInterstitialAd) {
        print("Interstitial ad dismissed")
        // Preload next ad
        loadInterstitialAd()
    }

    // Full screen ad show failed (optional)
    func onAdFailedToShowFullScreen(_ ad: AdropInterstitialAd, _ errorCode: AdropErrorCode) {
        print("Interstitial ad failed to show: \(errorCode)")
    }
}

SwiftUI Implementation

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

Method 1: ViewModel Pattern

import SwiftUI
import AdropAds

// ViewModel
class InterstitialAdViewModel: NSObject, ObservableObject {
    @Published var isAdReady = false
    @Published var isAdShowing = false

    private var interstitialAd: AdropInterstitialAd?

    init() {
        loadAd()
    }

    func loadAd() {
        interstitialAd = AdropInterstitialAd(unitId: "YOUR_UNIT_ID")
        interstitialAd?.delegate = self
        interstitialAd?.load()
    }

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

        interstitialAd.show(fromRootViewController: rootViewController)
    }
}

// Delegate
extension InterstitialAdViewModel: AdropInterstitialAdDelegate {
    func onAdReceived(_ ad: AdropInterstitialAd) {
        DispatchQueue.main.async {
            self.isAdReady = true
        }
    }

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

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

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

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

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

            Button("Show Interstitial Ad") {
                adViewModel.showAd()
            }
            .disabled(!adViewModel.isAdReady)
            .padding()
        }
    }
}

Delegate Methods

Required Methods

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

Optional Methods

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

Closure Callbacks

As an alternative to delegates, you can use closure-based callbacks.
let interstitialAd = AdropInterstitialAd(unitId: "YOUR_UNIT_ID")

// Required
interstitialAd.onAdReceived = { ad in
    print("Ad received")
}
interstitialAd.onAdFailedToReceive = { ad, errorCode in
    print("Ad failed: \(errorCode)")
}

// Optional
interstitialAd.onAdImpression = { ad in print("Ad impression") }
interstitialAd.onAdClicked = { ad in print("Ad clicked") }
interstitialAd.onAdWillPresentFullScreen = { ad in print("Ad will present") }
interstitialAd.onAdDidPresentFullScreen = { ad in print("Ad did present") }
interstitialAd.onAdWillDismissFullScreen = { ad in print("Ad will dismiss") }
interstitialAd.onAdDidDismissFullScreen = { ad in print("Ad did dismiss") }
interstitialAd.onAdFailedToShowFullScreen = { ad, errorCode in print("Ad failed to show: \(errorCode)") }
If both a delegate and closures are set, both will be called.

Best Practices

1. Preload Ads

Preload ads before displaying them to improve user experience.
class GameViewController: UIViewController {
    private var interstitialAd: AdropInterstitialAd?
    private var isAdReady = false

    override func viewDidLoad() {
        super.viewDidLoad()
        // Preload when entering screen
        preloadInterstitialAd()
    }

    private func preloadInterstitialAd() {
        interstitialAd = AdropInterstitialAd(unitId: "YOUR_UNIT_ID")
        interstitialAd?.delegate = self
        interstitialAd?.load()
    }

    func onGameLevelComplete() {
        // Show immediately when level completes
        if isAdReady {
            interstitialAd?.show(fromRootViewController: self)
        }
    }
}

extension GameViewController: AdropInterstitialAdDelegate {
    func onAdReceived(_ ad: AdropInterstitialAd) {
        isAdReady = true
    }

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

    func onAdDidDismissFullScreen(_ ad: AdropInterstitialAd) {
        isAdReady = false
        // Preload next ad
        preloadInterstitialAd()
    }
}

2. Appropriate Display Timing

Display ads at natural transition points in your app.
// Good example: Game level transition
func onLevelComplete() {
    saveProgress()
    showInterstitialAd()
    loadNextLevel()
}

// Good example: Content reading complete
func onArticleFinished() {
    showInterstitialAd()
}

// Bad example: During user action
func onButtonTap() {
    showInterstitialAd() // Disrupts user experience
    performAction()
}

3. Reload After Dismissal

Preload the next ad after the ad is dismissed.
func onAdDidDismissFullScreen(_ ad: AdropInterstitialAd) {
    // Immediately load next ad
    loadInterstitialAd()
}

4. Error Handling

Implement error handling for ad load failures.
func onAdFailedToReceive(_ ad: AdropInterstitialAd, _ errorCode: AdropErrorCode) {
    switch errorCode {
    case .ERROR_CODE_NETWORK:
        print("Network error: Retry later")
        retryAfterDelay()
    case .ERROR_CODE_AD_NO_FILL:
        print("No available ads")
        continueWithoutAd()
    default:
        print("Ad load failed: \(errorCode)")
    }
}

private func retryAfterDelay() {
    DispatchQueue.main.asyncAfter(deadline: .now() + 30) {
        self.loadInterstitialAd()
    }
}

5. Frequency Capping

Limit how often ads are displayed to avoid being too intrusive.
class AdFrequencyManager {
    private var lastAdShownTime: Date?
    private let minimumInterval: TimeInterval = 180 // 3 minutes

    func canShowAd() -> Bool {
        guard let lastTime = lastAdShownTime else {
            return true
        }

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

    func recordAdShown() {
        lastAdShownTime = Date()
    }
}

// Usage example
let frequencyManager = AdFrequencyManager()

func showInterstitialIfAllowed() {
    guard frequencyManager.canShowAd() else {
        print("Ad display interval too short")
        return
    }

    interstitialAd?.show(fromRootViewController: self)
}

func onAdDidPresentFullScreen(_ ad: AdropInterstitialAd) {
    frequencyManager.recordAdShown()
}

Next Steps

Rewarded Ads

Improve user engagement with rewarded ads

Banner Ads

Implementing banner ads

Targeting Settings

User attributes and contextual targeting

Reference

API reference documentation