Interstitial Ads

Interstitial ads are full screen ads that are overlayed on top of an application. They are generally displayed at natural app transition points such as in between game levels.

This guide explains how to integrate interstitial ads into your DFP Mobile Ads iOS application.

Prerequisites

Helpful primers

  • You can download the interstitial example from GitHub and follow along with adding interstitial ads to your project.

    Objective-C Swift

  • You may want to also read the ad events guide in order to take full advantage of interstitial ads. Some examples in this guide use ad events to perform more advanced interstitial integrations.

Create an interstitial ad unit in DFP

Create an ad unit in DFP to represent the interstitial ad unit. Interstitial ad units can be defined with one of the four common sizes, regardless of the actual screen size of individual devices. The SDK will handle rendering the creative correctly on screens which are of slightly different sizes.

  • Phones: 320x480 (portrait), 480x320 (landscape)
  • Tablets: 768x1024 (portrait), 1024x768 (landscape)

There is no need to define a separate ad unit for landscape mode. You can simply add the landscape size (for example, 480x320 for smartphones) to line items targeting the interstitial ad unit and include a creative with the landscape size in addition to the regular portrait size.

Adding interstitial ads to your project

The recommended lifecycle for a DFPInterstitial is to preload it when the app starts, and show it at a natural stopping point in your app. The example code in this guide shows how interstitials work inside of a game. It loads an interstitial each time the game starts and shows the interstitial when the game ends.

This snippet shows how to create and load a DFPInterstitial when the game starts.

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, UIAlertViewDelegate {

  var interstitial: DFPInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()

    startNewGame()
  }

  fileprivate func startNewGame() {
    createAndLoadInterstitial()

    // Set up a new game.
  }

  fileprivate func createAndLoadInterstitial() {
    interstitial = DFPInterstitial(adUnitID: "/6499/example/interstitial")
    interstitial.load(DFPRequest())
  }
}

Objective-C

@import GoogleMobileAds;

@interface ViewController () <UIAlertViewDelegate>

@property(nonatomic, strong) DFPInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [self startNewGame];
}

- (void)startNewGame {
  [self createAndLoadInterstitial];

  // Set up a new game.
}

- (void)createAndLoadInterstitial {
  self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"/6499/example/interstitial"];
  [self.interstitial loadRequest:[DFPRequest request]];
}

When you are ready to show an interstitial, check if it's ready before attempting to display it. Here's an example of showing the interstitial when a game is over. The app must explicitly call this method at the appropriate time.

Swift

fileprivate func endGame() {
  UIAlertView(title: "Game Over",
              message: "Your time ran out!",
              delegate: self,
              cancelButtonTitle: "Ok").show()
}

func alertView(_ alertView: UIAlertView, willDismissWithButtonIndex buttonIndex: Int) {
  if interstitial.isReady {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
  // Give user the option to start the next game.
}

Objective-C

        - (void)endGame {
          [[[UIAlertView alloc]
                  initWithTitle:@"Game Over"
                        message:@"Your time ran out!"
                       delegate:self
              cancelButtonTitle:@"Ok"
              otherButtonTitles:nil] show];
        }

        - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
          if (self.interstitial.isReady) {
            [self.interstitial presentFromRootViewController:self];
          } else {
            NSLog(@"Ad wasn't ready");
          }
          // Give user the option to start the next game.
        }

The result

Here is what the app looks like when an interstitial is shown.

Only show DFPInterstitial once

DFPInterstitial is a one time use object. That means once an interstitial is shown, hasBeenUsed returns true and the interstitial can't be used to load another ad. To request another interstitial, you'll need to create a new DFPInterstitial object. The best practice, as shown above, is to have a helper method to handle creating and loading an interstitial.

FAQ

How do I optimize the user experience for my interstitial ads?
Check out our interstitial implementation guidelines.
I'm getting the message "Cannot present interstitial. It is not ready".
This error means the interstitial ad was not successfully fetched. To prevent this warning from happening, use the isReady method to check if the interstitial is ready to present.
I'm getting the error "Request Error: Will not send request because interstitial object has been used".
Interstitials are a one time use object. You must create a new interstitial object to make another interstitial ad request.
I'm not getting any ads back, with the error response "Request Error: No ads to show".
Make sure your line item has a creative targeted to the right size. Interstitial sizes are 320x480 & 480x320 for phones and 1024x768 & 768x1024 for tablets. If a device isn't big enough to fit a 1024x768 or 768x1024, it will fall back to the 320x480 or 480x320 size.

Send feedback about...

SDK for DFP Users on iOS
Need help? Visit our support page.