1. Home
  2. Docs
  3. IOS – Monetize App ...
  4. User Manual
  5. Ad Formats
  6. Interstitial

Interstitial

Prerequisites

Load & Show the Ad

Consider a scenario where a button click triggers an Interstitial and, subsequently, the NewViewController is launched from MainViewController.

Load

To load Interstitial Ad use RefineryAdFactory.shared.createInterstitial method inside the super.viewDidLoad of the MainViewController.

class MainViewController: UiViewControlelr {
    var interstitialId:Int32 = -1;
    …
    override func viewDidLoad() {
        super.viewDidLoad()
        …
        let interstitialAdId = ConfigBuilder.companion.INTERSTITIAL_TEST_R89_CONFIG_ID
        interstitialId = RefineryAdFactory.shared.createInterstitial(configurationID: interstitialAdId, uiViewController: self, afterInterstitial: {
            // This callback is called when interstital closed or failed to load.
            // Here the navigation flow continus
            self.present(NewViewController(), animated: true)
        }, lifecycleCallbacks: nil)
    }
    …
}
    

As we can observe in the afterInterstitial callback, as soon as the interstitial get closed the navigation to NewViewController will take place.

Show on Button Press

Some events take place in your app, such as a button press, tab change or opening a link.

If the Interstitial hasn’t Loaded yet or failed to load when you call show, the flow will continue normally.


        class MainViewController: UiViewControlelr {
            …
            override func viewDidLoad() {
                super.viewDidLoad()
                …
                // Set up an action on uiButton to display loaded interstitial with it’s interstitialId.
                uiButton.addAction(UIAction(handler: {_ in
                    RefineryAdFactory.shared.show(index: self.interstitialId)
                }), for: .touchUpInside)
            }
            …
        }
    

Show on Creation of the Interstitial

In contrast to the previous example, where the interstitial ad was preliminarily loaded inside the viewDidLoad method, now the interstitial ad will be loaded after the button press event.

        class MainViewController: UiViewControlelr {
            …
            override func viewDidLoad() {
                super.viewDidLoad()
                …
                // Set up an action on uiButton to display loaded interstitial with it’s interstitialId.
                uiButton.addAction(UIAction(handler: {_ in
                    createInterstitial()
                }), for: .touchUpInside)
            }
            …
        }
    

Here is the implementation of the createInterstitial() method.

class MainViewController: UiViewControlelr {
    override func viewDidLoad() { … }
    …
    func createInterstitial(){
        let interstitialAdId = ConfigBuilder.companion.INTERSTITIAL_TEST_R89_CONFIG_ID
        interstitialId = RefineryAdFactory.shared.createInterstitial(configurationID: interstitialAdId, uiViewController: self, afterInterstitial: {
            // Here the navigation flow continus
            self.present(NewViewController(), animated: true)
        }, lifecycleCallbacks: InterstitialEventListenerDelegate(viewController: self))
    }
}
    

The instance of InterstitialEventListenerDelegate is passed to the lifecycleCallbacks parameter. The InterstitialEventListenerDelegate will be notified whenever the interstitial gets loaded or fails to load.

class InterstitialEventListenerDelegate : InterstitialEventListener {

    let viewController:LunchScreenViewController
    
    init(viewController: LunchScreenViewController) {
        self.viewController = viewController
    }
    
    override func onLoaded() {
        RefineryAdFactory.shared.show(index: viewController.interstitialId)
    }
    
    override func onFailedToLoad(error: R89LoadError) {
        RefineryAdFactory.shared.show(index: viewController.interstitialId)
    }
}
    

This will increase the time it takes to perform the user action.

Because its making the Ad Request when the user takes the action. You should use the previous approach where we make the request and store the ad ID for instant showing it when the user performs the actions.

This is how we use Interstitial we use in Demos.


Lifecycle Events

To observe the lifecycle methods of the interstitial create an instance of InterstitialEventListenerDelegate and pass it to RefineryAdFactory.shared.createInterstitial method.
Following methods are available.

        private class LoggerInterstitialEventListener : InterstitialEventListener {
            override func onLoaded() {
                print(“onLoaded”)
            }
            
            override func onFailedToLoad(error: R89LoadError) {
                print(“onFailedToLoad”,”error=\(error)”)
            }
            
            override func onOpen() {
                print(“onOpen”)
            }
            
            override func onClick() {
                print(“onClick”)
            }
            
            override func onImpression() {
                print(“onImpression”)
            }
            
            override func onAdDismissedFullScreenContent() {
                print(“onAdDismissedFullScreenContent”)
            }
            
            override func onAdFailedToShowFullScreen(errorMsg: String) {
                print(“onAdFailedToShowFullScreen”,”errorMsg=\(errorMsg)”)
            }
        }
    

As you can see onClose is not present because we have the afterInterstitial event that is mandatory to pass as a parameter to RefineryAdFactory.shared.createInterstitial method and holds the same functionality as onClose with special cases.

After Interstitial

This is not passed as a separated object like the other Events because is mandatory to handle what happens after an Interstitial is closed. This is invoked in the SDK when:

  • Everything went right and the user just closed the full-screen ad.

  • The ad hasn’t loaded yet and you tried to show it.

  • The ad has been Invalidated and you tried to show it. Gets invalidated when:

    • Fails to load.

    • Already shown.

    • Too Long without showing it.

  • The ad failed to show.

How can we help?