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:
- Prepare your UIViewController
- Set up and load an interstitial ad
- Display the interstitial ad
- 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.delegate = nil; self.interstitialAd = nil; } @end
Using Swift:
class InterstitialAdViewController: UIViewController { var interstitialAd: FAInterstitialAd? = nil override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) interstitialAd?.cancel() interstitialAd?.delegate = nil 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; } if ([FAInterstitialAd isAvailableForPlacementId:@"your-placement-id"]) { // Setup FAInterstitialAdConfig FAInterstitialAdConfig *config = [FAInterstitialAdConfig new]; config.placementId = @"your-placement-id"; // Setup your FAInterstitialAd instance self.interstitialAd = [[FAInterstitialAd alloc] initWithConfig:config]; 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") { // Setup FAInterstitialAdConfig let config = FAInterstitialAdConfig() config.placementId = "your-placement-id" // Setup your FAInterstitialAd instance interstitialAd = FAInterstitialAd(config: config) 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 or playback of an ad
- (void)interstitialAd:(FAInterstitialAd *)interstitialAd didFailWithError:(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;
Ad Request Options
The class FAInterstitialAdConfig
provides additional properties that allow you specify optional details about the context of an ad placement.
Property Name | Description |
---|---|
contentURL |
iOS Universal Link for the screen where the ad will be displayed. |
customParameters |
Specify custom parameters to pass additional tracking data about the context of your placement. For example, this could be the category of a certain item an user viewed in your app. |
placementType |
Type of the placement. See FAPlacementType for available options. |
webContentURL |
Can be an iOS Universal Link or a regular website URL to the equivalent page on the publisher's website for the screen where the ad will be displayed. |