Skip to content

Interstitial Ads

Interstitial ads are full-screen advertisements that appear at natural transition points in an app, such as between levels or screens.

Create BoldwinInterstitial

To create an interstitial ad, start by initializing a BoldwinInterstitial with the following parameter:

  • placementID - A string used to identify the ad placement
let interstitial = BoldwinInterstitial(placementID: placementID)

Ad Sizes

A single ad unit can be configured to support multiple ad sizes:

interstitial.adSizes = [.init(width: 320, height: 480), .init(width: 768, height: 1024)]

Note: By setting this property you replace the ad sizes specified during initialization.

If ad sizes are not specified, the SDK automatically determines the optimal sizes for the device.

SKOverlay

By default, BoldwinInterstitial enables SKOverlay, allowing ads to leverage Apple's SKOverlay functionality. If needed, developers can disable this feature by setting the supportSKOverlay flag to false, which prevents the interstitial from using SKOverlay.

Ad Events

You can optionally assign a delegate to receive callbacks for ad events:

interstitial.delegate = self
// MARK: - BoldwinInterstitialDelegate
extension InterstitialViewController: BoldwinInterstitialDelegate {

    func interstitialDidReceiveAd(
        _ interstitial: BoldwinInterstitial,
        ad: BoldwinAd
    ) {
        // Called when ad is loaded.
    }

    func interstitial(
        _ interstitial: BoldwinInterstitial,
        didFailToReceiveAdWithError error: BoldwinError?
    ) {
        // Called when Boldwin SDK failed to load ad.
        print("SDK did fail to load ad with error: \(String(describing: error?.localizedDescription))")
    }

    func interstitialWillPresentAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial is about to be presented.
    }

    func interstitialDidDismissAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial is dismissed.
    }

    func interstitialDidClickAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial was clicked.
    }

    func interstitialWillLeaveApplication(_ interstitial: BoldwinInterstitial) {
        // Called when the application is about to enter the background.
    }
}

Ad Metadata

You can access the information about the loaded ad in interstitialDidReceiveAd delegate method. View the details here: BoldwinAd.

Load Ad

Once BoldwinInterstitial is configured, start loading the ad:

interstitial.loadAd()

Display the Ad

To display an interstitial ad, verify that it is ready using the isReady property, and then present it by calling show(from:):

if interstitial.isReady {
    interstitial.show(from: self)
}

See the complete integration example below:

import Boldwin

class InterstitialViewController: UIViewController {

    private var boldwinInterstitial: BoldwinInterstitial?

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

    private func createAd() {
        // 1. Create BoldwinInterstitial instance.
        let interstitial = BoldwinInterstitial(placementID: "<YOUR_PLACEMENT_ID>")

        // 2. Optionally set delegates
        interstitial.delegate = self

        // Store instance
        self.boldwinInterstitial = interstitial

        // 3. Load ad.
        interstitial.loadAd()
    }

    @IBAction func showInterstitial() {
        // 4. Check if ad is ready to be displayed.
        if boldwinInterstitial?.isReady == true {

            // 5. Show the ad.
            boldwinInterstitial?.show(from: self)
        } else {
            print("Interstitial not ready")
        }
    }
}

// MARK: - BoldwinInterstitialDelegate
extension InterstitialViewController: BoldwinInterstitialDelegate {

    func interstitialDidReceiveAd(
        _ interstitial: BoldwinInterstitial,
        ad: BoldwinAd
    ) {
        // Called when ad is loaded.
    }

    func interstitial(
        _ interstitial: BoldwinInterstitial,
        didFailToReceiveAdWithError error: BoldwinError?
    ) {
        // Called when Boldwin SDK failed to load ad.
        print("SDK did fail to load ad with error: \(String(describing: error?.localizedDescription))")
    }

    func interstitialWillPresentAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial is about to be presented.
    }

    func interstitialDidDismissAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial is dismissed.
    }

    func interstitialDidClickAd(_ interstitial: BoldwinInterstitial) {
        // Called when interstitial was clicked.
    }

    func interstitialWillLeaveApplication(_ interstitial: BoldwinInterstitial) {
        // Called when the application is about to enter the background.
    }
}