Interstital

Interstitial ads are full-screen ads that cover the interface of an app until closed by the user. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app.

This guide shows you how to integrate interstitial ads into an iOS app.

Prerequisites

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account. The easiest way to load test ads is to use our dedicated test ad unit ID for app interstitial ads:

63a573a507ebe

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

Implementation

The main steps to integrating interstitial ads are:

  • Load an ad

  • Register for callbacks

  • Display the ad and handle the event

Load an ad

Loading an ad is accomplished using the static loadAdWithPlacementID: method on the Adx3InterstitialAd class. The load method requires your ad unit ID, a userId object, and a completion handler which gets called when ad loading succeeds or fails. userId object can not be passed or your custom user identifier. The below example shows how to load an Adx3InterstitialAd in your ViewController class.

import UIKit

class ViewController: UIViewController, Adx3InterstitialDeleagte {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadInterstitialAd()
        // Do any additional setup after loading the view.
    }
    
    func loadInterstitialAd() {
        Adx3InterstitialAd.sharedManager().load(withPlacementID: "Your Placement ID", userId: "", delegate: self) { isSuccess in
            
        }
    }

}

Register for callbacks

You should rely on the Adx3InterstitialDelegate (optional) to handle display events and request events. The following code shows how to implement the protocol:

import UIKit

class ViewController: UIViewController, Adx3InterstitialDeleagte {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

extension ViewController {
    
    func didFinishLoadingAD(withPlacementID placementID: String!) {
        print("----Interstitial AD Load Finish----")
    }
    
    func didFailToLoadAD(withPlacementID placementID: String!, error: Error!) {
        print("----\(error.debugDescription)----")
    }
    
    func interstitialDidShow(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidClose(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidEndPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidStartPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
    
    }
    
    func interstitialFailedToShow(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidFailToPlayVideo(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
}

Display the ad

Interstitials should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task. Here's an example of how to do this in one of the action methods in a UIViewController:

func showInterstitialAd() {
    Adx3InterstitialAd.sharedManager().showInterstitial(in: self, delegate: self)
}

Last updated