Home / iOS / Swift / Interstitials

Swift

Interstitials

Interstitial is an ad shown in full-screen, with the option to close it.

Now you need to initialize the Interstitial in the ViewController.swift file.

Example:

import UIKit

class ViewController: UIViewController
{
var tappxInterstitial: TappxInterstitialViewController?
override func viewDidLoad() {
super.viewDidLoad()
self.tappxInterstitial = TappxInterstitialViewController(delegate: self)
self.tappxInterstitial?.setAutoShowWhenReady(true)
self.tappxInterstitial?.load()
}
}

extension ViewController: TappxInterstitialViewControllerDelegate {

func presentViewController() -> UIViewController! {
return self;
}
}

If you want to request an interstitial to be shown as soon as it's ready, use this method:

self.tappxInterstitial?.setAutoShowWhenReady(true)

If you want to have more control, you can use the following three options: load, isReady and show.

load is the request to get the ad and load all the information so you can show the ad.

self.tappxInterstitial?.load()

isReady allows you to check if the ad is ready to be shown. You will receive a "true" if the ad is ready and a "false" if not.

self.tappxInterstitial?.isReady

show allows you to display the interstitial ad that has loaded previously.

self.tappxInterstitial?.show()

These three options are useful in games, for example, if you want to load the ad while the user is playing and show it immediately after the user finishes playing.


Delegates

You can add listener events into the Interstitial to be notified when a specific event happens in the ad. Here you have examples:

extension AdViewController: TappxInterstitialViewControllerDelegate {
func tappxInterstitialViewControllerDidFinishLoad(_ viewController: TappxInterstitialViewController!) {
print("INTERSTITIAL: FinishLoad")
}
func tappxInterstitialViewControllerDidFail(viewController: TappxInterstitialViewController!, withError error: Error!) {
print("INTERSTITIAL: Failed %@", error.localizedDescription)
}
func tappxInterstitialViewControllerDidPress(_ viewController: TappxInterstitialViewController!) {
print("INTERSTITIAL: DidPress")
}
func tappxInterstitialViewControllerDidClose(_ viewController: TappxInterstitialViewController!) {
print("INTERSTITIAL: DidClose")
}
func tappxInterstitialViewControllerDidAppear(_ viewController: TappxInterstitialViewController!) {
print("INTERSTITIAL: DidAppear")
}
}