Interstitial Ads

iOS Interstitial Ads implementation

Interstitial ads use a full-screen experience that is typically shown during natural transition points in your app - for example between levels of a game, or while waiting for new content to load. MobileFuse offers both rich media and video interstitial ads, and the SDK will automatically choose the highest performing ad available for display.

Prerequisites

Display an interstitial ad in your app

Displaying an interstitial ad is a two-step process. First you should create and load your InterstitialAd unit, then when you’re ready, call the showAd() method to display the ad.

  • Create an interstitial ad unit
  • Display the ad

Create an interstitial ad unit

The MFInterstitialAd class provided by the MobileFuse SDK will handle the loading and display of the full-screen ads.

📘

Tip

To provide a good user experience, you should create and pre-load your interstitial ad units as soon as your app is launched. Once an interstitial ad unit is created and pre-loaded, you can display it instantly with the showAd() method. Having the ad preloaded will ensure that you’re ready to display the ad as soon as the interstitial opportunity occurs. However, please note that ads expire after 5 minutes (at which time you’ll need to request a new one), so plan accordingly.

First, create a new MFInterstitialAd unit and keep a reference to it:

@property (nonatomic, strong, readwrite) MFInterstitialAd *interstitialAd;

self.interstitialAd = [[MFInterstitialAd alloc] initWithPlacementId:@"<Interstitial placement ID>"];

📘

Note

Ensure that the SDK has fully initialized before creating your ad units. You can use the onInitSuccess callback as a good place to set up your ad units.

Next, add a delegate receiver- this will allow you to receive events from the ad unit.

[self.interstitialAd registerAdCallbackReceiver:self];
// ...

// IMFAdCallbackReceiver delegate implementation
- (void)onAdLoaded:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdLoaded with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}

- (void)onAdRendered:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdRendered with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}

- (void)onAdClicked:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdClicked with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}

- (void)onAdNotFilled:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdClicked with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}

- (void)onAdClosed:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdClosed with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}

- (void)onAdExpired:(MFAd *)ad {
    NSLog(@"IMFAdCallbackReceiver::onAdExpired with ad instance: %@ (Placement ID: %@)", [ad description], ad.placementId);
}
@interface ViewController : UIViewController<..., IMFAdCallbackReceiver>

Add the ad instance as a subview:

[self.view addSubview:self.interstitialAd];

Finally, request that the ad is preloaded using the loadAd method:

[self.interstitialAdInstance loadAd];

It’s also recommended you ensure that UI manipulation stays on the main thread. Here is a complete example:

// UI on main thread
dispatch_async(dispatch_get_main_queue(), ^ {
    self.interstitialAdInstance = [[MFInterstitialAd alloc] initWithPlacementId:self.interstitialPlacementId];
    [self.interstitialAdInstance registerAdCallbackReceiver:self];
    [self.view addSubview:self.interstitialAdInstance];

    [self.interstitialAdInstance loadAd];
});

Display the ad

Once the interstitial ad has triggered the onAdLoaded callback, you can then call showAd to instantly display the ad:

[self.interstitialAd showAd];

You can also use isLoaded to check whether the ad is ready to be displayed.

if([self.interstitialAd isLoaded] == YES) {
    // The ad is ready to be displayed!
}

📘

Note

Once you call showAd() on an instance, the loaded ad will be displayed. Since a loaded ad can only be displayed once, you must call loadAd() again once the ad is closed to get a new ad ready to display.