Request and display interstitial ads

The process of showing interstitial ads

Before showing the interstitial ads to your users they first need to be requested from our servers. The process can be summarized in the following three steps:

  1. Check availability of interstitial ad
  2. Display an interstitial ad

Request interstitial ads

  1. Make sure the FyberSDK.h file is imported. You can do this by including the following statement at the beginning of the file you’re working with:

    #import "FyberSDK.h"
    
  2. Make sure you’ve initialized the SDK previously as described in the Getting started with Fyber SDK section of this document.

  3. Get the Interstitial controller and request the offers

// Get the Interstitial Controller
FYBInterstitialController *interstitialController = [FyberSDK interstitialController];
interstitialController.delegate = self;

// request the offers
[interstitialController requestInterstitial];

Requesting and showing interstitials are asynchronous operations. To be notified of the availability of ads and of other events in the life of the interstitial, you can make one of your classes conform to the FYBInterstitialControllerDelegate protocol and register it as the interstitial controller’s delegate via its delegate property.

To check if there are any interstitials available call requestInterstitial on your FYBInterstitialController instance. The Fyber SDK will determine if it can show an interstitial and message your FYBInterstitialControllerDelegate callback when an interstitial is available:

- (void)interstitialControllerDidReceiveInterstitial:(FYBInterstitialController *)interstitialController
{
	// If there are offers to receive
}

And when not:

- (void)interstitialController:(FYBInterstitialController *)interstitialController
        failedToReceiveInterstitialWithError:(NSError *)error
{
	// If there are no offers    
}

We recommend doing this close to the actual point of showing an ad to the user, but not immediately before, as the process of requesting ads can take some time. Additionally, some networks are pre-caching the interstitial, and therefore by allowing for some time between the request and display of the ad you can be sure that the user experience will be the best.

Display interstitial ads

Once you have gotten a response indicating that there are ads available, call:

[interstitialController presentInterstitialFromViewController:self];

Your delegate will then be notified once the interstitial ad is successfully displayed:

- (void)interstitialControllerDidPresentInterstitial:(FYBInterstitialController *)interstitialController
{

}

and when the interstitial ad is dismissed

- (void)interstitialController:(FYBInterstitialController *)interstitialController
        didDismissInterstitialWithReason:(FYBInterstitialControllerDismissReason)reason
{

}

Note that the reason why the interstitial was dismissed may not be known, in particular if the underlying mediated SDK does not notify its client of whether an interstitial ad was clicked or just dismissed by the user.

You can use the delegates calls to pause and unpause your app’s sound when the ad will be presented or dismissed.

If an error happens at any point during this cycle the selector

- (void)interstitialController:(FYBInterstitialController *)interstitialController
        failedToReceiveInterstitialWithError:(NSError *)error
{

}

will be invoked in the delegate you registered with an NSError* instance encapsulating the cause of the error.

Example: Requesting and Showing and Interstitial Ad:

- (void)interstitialController:(FYBInterstitialController *)interstitialController
        didDismissInterstitialWithReason:(FYBInterstitialControllerDismissReason)reason
{
    NSString *reasonDescription;
    switch (reason) {
        case FYBInterstitialControllerDismissReasonUserEngaged:
            reasonDescription = @"because the user clicked on it";
            break;
        case FYBInterstitialControllerDismissReasonAborted:
            reasonDescription = @"because the user explicitly closed it";
            break;
        case FYBInterstitialControllerDismissReasonError:
            break;
    }
    NSLog(@"The interstitial ad was dismissed %@", reasonDescription);
}


- (void)interstitialController:(FYBInterstitialController *)interstitialController
        failedToReceiveInterstitialWithError:(NSError *)error
{
    NSLog(@"An error occured while requesting or showing the interstitial %@", error);
}