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.
- Objective C
- Swift
#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
import BlueStackSDK
class ViewController: UIViewController {
var interstitialAd: InterstitialAd?
override func viewDidLoad() {
super.viewDidLoad()
interstitialAd = InterstitialAd(placementID: "INTERSTITIAL_PLACEMENT_ID")
}
}
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.
- Objective C
- Swift
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];
let requestOptions = RequestOptions(
age: 25,
location: CLLocation.init(latitude: 48.87610, longitude: 10.453),
gender: .male,
keyword: "brand=myBrand;category=sport",
contentUrl: "https://my_content_url.com/"
)
interstitialAd?.load(requestOptions: requestOptions)
// Or
// 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.
- Objective C
- Swift
self.interstitialAd.delegate = self;
self.interstitialAd.fullScreenDelegate = self;
interstitialAd?.delegate = self
interstitialAd?.fullScreenDelegate = self
Interstitial ad lifecycle events
InterstitialAdDelegate
has the following methods for listening to interstitial ad's lifecycle events.
- Objective C
- Swift
- (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);
}
func onAdLoaded(_ ad: BlueStackSDK.InterstitialAd) {
print("Interstitial ad loaded")
}
func onAdFailedToLoad(_ ad: BlueStackSDK.InterstitialAd, _ error: any Error) {
print("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.
- Objective C
- Swift
- (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");
}
func onAdDisplayed(_ ad: any FullScreenDisplayableAd) {
print("Interstitial ad displayed")
}
func onAdFailedToDisplay(_ ad: any FullScreenDisplayableAd, _ error: any Error) {
print("Failed to display interstitial ad with error: \(error.localizedDescription)")
}
func onAdClicked(_ ad: any FullScreenDisplayableAd) {
print("Interstitial ad clicked.")
}
func onAdDismissed(_ ad: any FullScreenDisplayableAd) {
print("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.
- Objective C
- Swift
if (self.interstitialAd.isReady) {
[self.interstitialAd showFromRootViewController:self];
}
if interstitialAd.isReady
{
interstitialAd.show()
}
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
.
- Objective C
- Swift
self.interstitialAd = nil;
interstitialAd = nil
We discourage to create and load new interstitial ad instance in load failed callback onAdFailedToLoad(_ ad: , _ error:)
.