Aller au contenu principal
Version: 5.x.x

Interstitial Ads

Overview

Interstitial ads are full-screen, short clips that appears at natural transition points in an app. They come in various formats, including static (for image or text) and rich media (for video).

Create an Interstitial Ad

To create an interstitial ad, instantiate an instance of InterstitialAd with a placement Id.


#import <BlueStackSDK/BlueStackSDK.h>

@interface ViewController ()

@property (strong, nonatomic) InterstitialAd *interstitialAd;

@end

@implementation ViewController

- (void)viewDidLoad {
self.interstitialAd = [[InterstitialAd alloc] initWithPlacementID:@"INTERSTITIAL_PLACEMENT_ID"];
}

@end

Load an Interstitial Ad

Interstitial ad can be loaded by calling load(requestOptions:) method with a RequestOptions instance for supplying targeting information or simply calling load() method.

RequestOptions *requestOptions = [[RequestOptions alloc] initWithAge:@(25)
location:[[CLLocation alloc] initWithLatitude:48.87610 longitude:10.453]
gender:GenderMale
keyword:@"brand=myBrand;category=sport"
contentUrl:@"https://my_content_url.com/"];
[self.interstitialAd loadWithRequestOptions:requestOptions];
// Or
// [self.interstitialAd load];

Ad events

Register for interstitial events

InterstitialAd provides lifecycle events and other full-screen events through InterstitialAdDelegate and FullScreenDelegate. Use following code to listen to all the events that interstitial ad invokes.

self.interstitialAd.delegate = self;
self.interstitialAd.fullScreenDelegate = self;

Interstitial ad lifecycle events

InterstitialAdDelegate has the following methods for listening to interstitial ad's lifecycle events.

- (void)didLoadInterstitialAd:(InterstitialAd *)ad {
NSLog(@"Interstitial ad loaded");
}

- (void)interstitialAd:(InterstitialAd *)ad didFailedToLoadWithError:(NSError *)error {
NSLog(@"Failed to load interstitial ad with error: %@", error.localizedDescription);
}

Interstitial ad full-screen events

FullScreenDelegate has the following methods for receiving full-screen content events.

- (void)didDisplayAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Interstitial ad displayed");
}

- (void)ad:(id<FullScreenDisplayableAd>)ad didFailedToDisplayWithError:(NSError *)error {
NSLog(@"Failed to display interstitial ad with error: %@", error.localizedDescription);
}

- (void)didClickAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Interstitial ad clicked.");
}

- (void)didDismissAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Interstitial ad dismissed");
}

Show an Interstitial Ad

To show an interstitial ad call show(fromRootViewController:) method on InterstitialAd instance with an optional root view controller.

if (self.interstitialAd.isReady) {
[self.interstitialAd showFromRootViewController:self];
}

Destroying an Interstitial Ad

You need to keep a strong reference to the InterstitialAd instance. You can release it when you are done showing the interstitial ad (Interstitial ad has dismissed) simply by setting it to nil.

self.interstitialAd = nil;
info

We discourage to create and load new interstitial ad instance in load failed callback onAdFailedToLoad(_ ad: , _ error:).