Integrating Interstitial Ads in iOS

This guide walks you through all necessary steps to integrate interstitial ads into your app.

If you have not done so already, please start with the Getting Started guide before reading on.


Integration

Overview

The FeedAd SDK manages the interstitial display logic, leaving the following steps up to you:

  1. Prepare your UIViewController
  2. Set up and load an interstitial ad
  3. Display the interstitial ad
  4. Implement what to do after the ad has been displayed

The integration will take you about 60 minutes.

1. Prepare your UIViewController

Create a property of your interstitial ad and make sure it is released when the user leaves the view controller before the ad was fully shown.

Using Objective-C:

@interface InterstitialAdViewController ()

@property (nonatomic, strong) FAInterstitialAd *interstitialAd;

@end


@implementation InterstitialAdViewController

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.interstitialAd cancel];
    self.interstitialAd = nil;
}

@end  

Using Swift:

class InterstitialAdViewController: UIViewController {
    var interstitialAd: FAInterstitialAd? = nil

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)

        interstitialAd?.cancel()
        interstitialAd = nil
    }
}

2. Set Up and Load an Interstitial Ad

To set up an instance of FAInterstitialAd, check the availability of the placement and initialize it with its placement ID. After making your view controller conform to FAInterstitialAdDelegate and setting the delegate on your new instance of FAInterstitialAd, simply call the load method to have it load an ad.

Placement ID?

You can choose placement IDs yourself. A placement ID should be named after the ad position inside your product. For example, if you want to display an ad inside a list of news articles, you could name it "ad-news-overview".
A placement ID may consist of lowercase a-z, 0-9, - and _. You do not have to manually create the placement IDs before using them. Just specify them within the code, and they will appear in the FeedAd admin panel after the first request. Learn more about Placement IDs and how they are grouped to play the same Creative

FAInterstitialAdDelegate

For a detailed description of the FAInterstitialAdDelegate and its methods see FAFeedAd Delegate Methods.

Using Objective-C:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if (self.interstitialAd) {
        return;
    }

    // Set up interstitial ad with placement id
    // The placement id may be chosen by the developer and
    // allows to distinguish different screens
    if ([FAInterstitialAd isAvailableForPlacementId:@"your-placement-id"]) {
        self.interstitialAd = [[FAInterstitialAd alloc] initWithPlacementId:@"your-placement-id"];
        self.interstitialAd.delegate = self;
        [self.interstitialAd load];
    }
}

Using Swift:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if let _ = interstitialAd {
        return
    }

    if FAInterstitialAd.isAvailable("your-placement-id") {
        interstitialAd = FAInterstitialAd(placementId: "your-placement-id")
        interstitialAd?.delegate = self
        interstitialAd?.load()
    }
}

3. Display the Interstitial Ad

After the interstitial ad has been loaded, i.e. interstitialAdDidFinishLoading: was called, it's ready to show. Simply call show on your FAInterstitialAd instance and the interstitial will pop up and automatically start playing.

4. Implement What to Do after the Ad Has Been Displayed

The UI of an FAInterstitialAd will show until the ad has finished playing or got skipped by the user. In both cases, the delegate method interstitialAdDidFinishPlaying: gets called, enabling you to execute some code afterwards.

Instances of FAInterstitialAd cannot be reused. If you would like to show another interstitial, you have to start over with a fresh instance of FAInterstitialAd.

It's a Wrap

Once you have completed all of the above steps, you should have a working interstitial ads integration.


FAInterstitialAd Delegate Methods

Implement the delegate methods from FAInterstitialAdDelegate to be notified about events and to customize its appearance:

  • Specify a view to show in the background
- (UIView *)backgroundViewForInterstitialAd:(FAInterstitialAd *)interstitialAd;
  • An ad has been loaded successfully
- (void)interstitialAdDidFinishLoading:(FAInterstitialAd *)interstitialAd;
  • An ad has played through successfully
- (void)interstitialAdDidFinishPlaying:(FAInterstitialAd *)interstitialAd;
  • Errors occured during loading of an ad
- (void)interstitialAd:(FAInterstitialAd *)interstitialAd didFailToLoadWithError:(NSError *)error;
  • Errors occured during playback of an ad
- (void)interstitialAd:(FAInterstitialAd *)interstitialAd didFailToPlayWithError:(NSError *)error;
  • An ad logged an impression
- (void)interstitialAdDidLogImpression:(FAInterstitialAd *)interstitialAd;
  • Should a loading indicator be displayed for this interstitial ad?
- (BOOL)interstitialAdShouldDisplayLoadingIndicator:(FAInterstitialAd *)interstitialAd;
  • An ad has been clicked
- (void)interstitialAdWasClicked:(FAInterstitialAd *)interstitialAd;
  • An ad has been skipped
- (void)interstitialAdWasSkipped:(FAInterstitialAd *)interstitialAd;
  • An ad will leave the application to show its landing page after the user has clicked the ad
- (void)interstitialAdWillLeaveApplication:(FAInterstitialAd *)interstitialAd;

Advanced Options

Custom parameters

You can set up an FAInterstitialAd with custom parameters to pass additional tracking data about the context in which the ad is played, e.g. the category of an item viewed by the user, using its dedicated initializer:

- (instancetype)initWithPlacementId:(NSString *)placementId customParameters:(NSDictionary<NSString *, NSString *> *)customParameters;