Search code examples
xcodeswiftiadinterstitial

Better way to show iAd interstitial ads


Is there a better way to show interstitial ads than just picking a random number between 0-4 and if its 3 show the ad?

This method has its downsides because sometimes ads wont show for awhile and other times they will show 3 times in a row which is very annoying. Any help would be appreciated!


Solution

  • Why generate a random number at all? There is no requirement for you to implement your interstitials in this manner. How often do you want to show your ads? You can just increment an index and show your interstitial once it reaches a certain amount. For example:

    // Create an Int to increment
    var index = 0
    
    // Call this func after an event
    func showInterstitial() {
        index++
        if (index == 5) {
            // Show ad
            // Reset index
            index = 0
        }
    }