Follow

Show Interstitial Ad

View original article on our GitHub
You can choose to show the interstitial ad in several locations within your application. This could be between stages, while waiting for an action, when pressing a button and more.

In your view controller declare STAStartAppAd at the begin of the class. Init STAStartAppAd within the viewDidLoad() method and load it within the viewDidAppear() method.

var startAppAd: STAStartAppAd?

override func viewDidLoad() {
        super.viewDidLoad()

        startAppAd = STAStartAppAd()
    }

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        startAppAd!.loadAd()
    }

Finally, add the following lines where you want to show the ad

startAppAd!.showAd()

IMPORTANT
Loading an ad might take a few seconds so it's important to show the ad as late as you can. In case you call showAd() while the ad hasn't been successfully loaded yet, nothing will be displayed. For example, if you'd like to show an ad after completing a game's level, the best practice would be to show the ad upon completing the level (for example in your viewDidDisappear() method). On the other hand, loading and showing the ad together at the beginning of the next level might result with a failure – as the ad might not have enough time to load.

Was this article helpful?
0 out of 1 found this helpful
Have more questions? Submit a request

Comments