Interstitial Ads - cleveradssolutions/CAS-iOS GitHub Wiki

⚡ Before you start
Make sure you have correctly configure user consent flow.


Interstitial ads are full-screen ads that cover the interface of their host app. 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 explains how to integrate interstitial ads into an Android app.

Load an ad

Note

By default, the auto-load ads mode is used and a load method does not need to be called. Call manual load ad before each show if you use CASLoadingManagerMode.manual only.

Manual load Interstitial ads.

Swift
manager.loadInterstitial()
Objective-C
[manager loadInterstitial];

You can get a callback for the successful loading of the ads:

Swift
class AnyViewController: UIViewController, CASLoadDelegate{
    
    override func viewDidLoad() {    
        super.viewDidLoad()
        manager.adLoadDelegate = self
    }
    
    func onAdLoaded(_ adType: CASType){
        if (adType == .interstitial){
            // Interstitial loaded
        }
    }
    
    func onAdFailedToLoad(_ adType: CASType, withError error: String?){
        if (adType == .interstitial){
            // Interstitial failed to load with error 
        }
    }
}
Objective-C
@interface ViewController : UIViewController>CASLoadDelegate>
@end

@implementation ViewController
- (void)viewDidLoad {  
  [super viewDidLoad];
  manager.adLoadDelegate = self; // Weak reference
}

- (void)onAdLoaded:(enum CASType)adType {
    if (adType == CASTypeInterstitial) {
        // Interstitial loaded
    }
}
- (void)onAdFailedToLoad:(enum CASType) adType withError:(NSString *)error {
   if (adType == CASTypeInterstitial) {
        // Interstitial failed to load with error
    }
}
@end

Check the ad availability

You can ask for the ad availability directly by calling the following function:

Swift
let adLoaded = manager.isInterstitialReady
Objective-C
BOOL adLoaded = self.manager.isInterstitialReady;

Ad Callback

The CASCallback handles events related to displaying your Interstitial ad.

Swift
class AnyViewController: UIViewController, CASCallback {

    func willShown(ad adStatus: CASStatusHandler){
        // Ad will present content
    }

    func didShowAdFailed(error: String){
      // Ad did fail to present content.
    }
 
    func didClickedAd(){
      // Ad did click content
    }

    func didCompletedAd(){
      // Ad did complete content
    }

    func didClosedAd(){
      // Ad did dismiss content.
    }
}
Objective-C
- (void)willShownWithAd:(id>CASStatusHandler>)adStatus {
    // Ad will present content
}

- (void)didShowAdFailedWithError:(_NSString_ *)error {
    // Ad did fail to present content.
}

- (void)didClickedAd {
    // Ad did click content
}

- (void)didCompletedAd {
    // Ad did complete content
}

- (void)didClosedAd {
    // Ad did dismiss content.
}

Warning

When an error occurs during ad impression, executed the didShowAdFailed(:) only.
didClosedAd() in this case will not be executed, since the impression is not considered successful.

Note

Read more about event willShown(ad:) with Impression level data.

Show the ad

The presentInterstitial() method requires UIViewController and CASCallback instances as arguments.

  • controller The controller from which the Interstitial ad should be shown.
  • callback The callback for Interstitial ad events. The reference to the callback is weak and may be removed from memory.
manager.presentInterstitial(fromRootViewController: self, callback: self)
Objective-C
[manager presentInterstitialFromRootViewController:self callback:self];

Muted Ad sounds

Indicates if the application’s audio is muted. Affects initial mute state for all ads.
Use this method only if your application has its own volume controls.

CAS.settings.muteAdSounds = false
Objective-C
CAS.settings.muteAdSounds = NO;

Minimum interval between impressions

You can limit the posting of an interstitial ad to a period of time in seconds after the ad is closed, during which display attempts will fail. Unlimited by default 0 seconds.
That the interval starts only after the Interstitial Ad closes CASCallback.didClosedAd(). During interval after ad closed, display attempts will fire event CASCallback.didShowAdFailed(error:) with CASError.intervalNotYetPassed.

You can specify minimal interval before initialization to allow overrides settings by the web interface for a given session.

Swift
CAS.settings.interstitialInterval = 0
Objective-C
CAS.settings.interstitialInterval = 0;

If you need to wait for a period of time after the start of the app or after showing a Rewarded Ad until next Interstitial Ad impression then call the following method:

Swift
CAS.settings.restartInterstitialInterval()
Objective-C
[CAS.settings restartInterstitialInterval];

Some best practices

  • All the rootViewController parameters in Ad APIs must be provided to process ad redirects. In the SDK, all redirects use the present method. Therefore, make sure that the passed rootViewController parameters are not null and do not have other present controllers. Otherwise the present will fail because presentedViewController already exists.
  • Consider whether interstitial ads are the right type of ad for your app.
    Interstitial ads work best in apps with natural transition points. The conclusion of a task within an app, like sharing an image or completing a game level, creates such a point. Because the user is expecting a break in the action, it's easy to present an interstitial ad without disrupting their experience. Make sure you consider at which points in your app's workflow you'll display interstitial ads and how the user is likely to respond.
  • Remember to pause the action when displaying an interstitial ad.
    There are a number of different types of interstitial ads: text, image, video, and more. It's important to make sure that when your app displays an interstitial ad, it also suspends its use of some resources to allow the ad to take advantage of them. For example, when you make the call to display an interstitial ad, be sure to pause any audio output being produced by your app.
  • Allow for adequate loading time.
    Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance by calling loadInterstitial before you intend to call presentInterstitial can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.
  • Don't flood the user with ads.
    While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.

🔗 Done! What’s Next?

⚠️ **GitHub.com Fallback** ⚠️