Skip to content

Interstitial

Warning

This is the documentation for the Advanced API. Most developers should use our Simplified API, which comes with several built-in features such as:

  • automatic ad loading

  • retries for failed requests

See the documentation for the Simplified API here:

An interstitial ad is a fullscreen format, usually skippable after the first few seconds of its display. Because of this, it's commonly used in transitions of the app or game, such as completing a level or navigating to a different screen.

Create an Interstitial instance

let interstitial = Interstitial.create(placementId: "<placement-id>")

Register ad callbacks

// Assign a delegate to handle the ad callbacks
interstitial.delegate = self

// [...]

// Load Callbacks

func didCompletePrebidding(result: PrebiddingResults) {
    print("Interstitial client-side bidding finished!")
}

func didLoad(result: LoadResult) {
    print("Interstitial loaded!")
}

func failedToLoad(result: LoadResult?, error: LoadError) {
    print("Interstitial failed to load. Reason: \(error.localizedDescription)")
}


// Show Callbacks

func didPresent() {
    print("Interstitial is being presented!")
}

func failedToPresent(error: PresentError) {
    // If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
    print("Interstitial failed to present. Reason: \(error.localizedDescription)")
}

func willDismiss() {
    print("Interstitial will be dismissed!")
}

func didDismiss() {
    // If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
    print("Interstitial was dismissed!")
}

func didClick() {
    print("Interstitial was clicked!")
}

func didRecordImpression(data: ImpressionData) {
    print("Interstitial impression, with revenue: \(data.revenue)")
}

Load an ad

interstitial.load()

Load an ad (with custom properties)

var properties = CustomProperties()
properties.addString(key: "game_mode", value: "classic")

interstitial.load(customProperties: properties)

Present an ad

if interstitial.isReady {        
    interstitial.present(fromViewController: self, fromAdSpace: "interstitial-ad-space")
}

Code example

InterstitialViewController.swift
import UIKit
import XMediator

class InterstitialViewController: UIViewController {
    private var interstitial: Interstitial?

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

    @IBAction func loadButtonTouchUpInside(_ sender: Any) {
        let interstitial = Interstitial.create(placementId: "<placement-id>")
        interstitial.delegate = self
        interstitial.load()

        self.interstitial = interstitial
    }

    @IBAction func presentButtonTouchUpInside(_ sender: Any) {
        if let interstitial = interstitial, interstitial.isReady {
            interstitial.present(fromViewController: self)
        }
    }
}

extension InterstitialViewController: InterstitialDelegate {
    // Load Callbacks
    func didCompletePrebidding(result: PrebiddingResults) {
        print("Interstitial client-side bidding finished!")
    }

    func didLoad(result: LoadResult) {
        print("Interstitial loaded!")
    }

    func failedToLoad(result: LoadResult?, error: LoadError) {
        print("Interstitial failed to load. Reason: \(error.localizedDescription)")
    }


    // Present Callbacks
    func didPresent() {
        print("Interstitial is being presented!")
    }

    func failedToPresent(error: PresentError) {
        // If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
        print("Interstitial failed to present. Reason: \(error.localizedDescription)")
    }

    func willDismiss() {
        print("Interstitial will be dismissed!")
    }

    func didDismiss() {
        // If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
        print("Interstitial was dismissed!")
    }

    func didClick() {
        print("Interstitial was clicked!")
    }

    func didRecordImpression(data: ImpressionData) {
        print("Interstitial impression, with revenue: \(data.revenue)")
    }
}