Interstitial Ad

app_show_type: 50000

Interstitial ads are full-screen ads that cover the interface of an app until closed by the user. 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 shows you how to integrate interstitial ads into an iOS app.

Import Header Files.

// if CheetahMobileAds.framework
@import CheetahMobileAds;

// else if CheetahMobileAds.a
#import "CMAInterstitial.h"

Create an interstitial ad object.

Interstitial ads are requested and shown by CMAInterstitial objects. The first step in using one is to instantiate it and set its ad posid. For example, here's how to create a CMAInterstitial in the viewDidLoad method of a UIViewController:

@interface ViewController ()<CMAInterstitialDelegate>

@property (nonatomic) CMAInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    CMAPosIDConfig *config = [[CMAPosIDConfig alloc] 
            initWithOrionPosID:@"YOUR_POSID_FOR_GLOBAL" 
            liehuPosID:@"YOUR_POSID_FOR_CHINA"];
    
    self.interstitial = [[CMAInterstitial alloc] initWithPosIDConfig:config];
}

CMAInterstitial is a single-use object that will load and display one interstitial ad. To display multiple interstitial ads, an app needs to create a CMAInterstitial for each one.

Set up event notifications

To set up event notifications, insert the line before your load request call.

self.interstitial.delegate = self;

The following sample illustrates how to log each of the events available in CMAInterstitialDelegate:

#pragma mark - CMAInterstitialDelegate Implimentions

- (void)interstitialDidLoadAd:(CMAInterstitial *)ad;
{
    NSLog(@"Ad was loaded.");
    [ad presentFromRootViewController:self];
}

- (void)interstitial:(CMAInterstitial *)ad didFailToLoadAdWithError:(CMARequestError *)error;
{
    NSLog(@"didFailToLoadAdWithError %@", error);
}

- (void)interstitialWillPresentScreen:(CMAInterstitial *)ad;
{
    NSLog(@"interstitialWillPresentScreen");
}

- (void)interstitialWillDismissScreen:(CMAInterstitial *)ad;
{
    NSLog(@"interstitialWillDismissScreen");
}

- (void)interstitialWillLeaveApplication:(CMAInterstitial *)ad;
{
    NSLog(@"interstitialWillLeaveApplication");    
}

@end

Load Ads

To load an interstitial ad, call loadAd: on a CMAInterstitial object:

[self.interstitial loadAd];

Show Ads

If the ad is loaded successfully, following function will be called!

- (void)interstitialDidLoadAd:(CMAInterstitial *)ad;
{
    NSLog(@"Ad was loaded.");
    
    // Then, you call show the ad.
    [ad presentFromRootViewController:self];
}

Last updated