Interstitial Integration for iOS
The Unity LevelPlay Interstitial is a full-screen ad unit, usually served at natural transition points during the app lifecycle.
- Make sure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.
- Make sure to initialize the SDK using LevelPlay Initialization API.
- You can find the AdUnitID in LevelPlay dashboard. Learn more here.
- This documentation is relevant for SDK 8.4.0+. Documentation for legacy interstitial APIs (SDK 8.4.0 and below) can be found here.
Create Interstitial Ad Object
The creation of the interstitial ad object should be done after receiving onInitSuccess callback.
self.interstitialAd = [[LPMInterstitialAd alloc] initWithAdUnitId:@"adUnitId"];
self.interstitialAd = LPMInterstitialAd(adUnitId: "adUnitId")
Implement Delegates
Implement the LPMInterstitialAdDelegate in your code to get informed of ad delivery.
- It is recommended to set the delegate before loading the interstitial ad.
- Please note that each interstitial ad should have its own delegate implementation.
- Delegate methods run on the main thread.
self.interstitialAd = [[LPMInterstitialAd alloc] initWithAdUnitId:@"adUnitId"];
self.interstitialAd.delegate = self;
#pragma mark - LPMInterstitialAdDelegate Methods
- (void)didLoadAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didFailToLoadAdWithAdUnitId:(NSString *)adUnitId error:(NSError *)error {}
- (void)didChangeAdInfo:(LPMAdInfo *)adInfo {}
- (void)didDisplayAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didFailToDisplayAdWithAdInfo:(LPMAdInfo *)adInfo error:(NSError *)error {}
- (void)didClickAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didCloseAdWithAdInfo:(LPMAdInfo *)adInfo {}
self.interstitialAd = LPMInterstitialAd(adUnitId: "adUnitId")
self.interstitialAd.setDelegate(self)
// MARK: LPMInterstitialAdDelegate methods
func didLoadAd(with adInfo: LPMAdInfo) {}
func didFailToLoadAd(withAdUnitId adUnitId: String, error: Error) {}
func didChangeAdInfo(_ adInfo: LPMAdInfo) {}
func didDisplayAd(with adInfo: LPMAdInfo) {}
func didFailToDisplayAd(with adInfo: LPMAdInfo, error: Error) {}
func didClickAd(with adInfo: LPMAdInfo) {}
func didCloseAd(with adInfo: LPMAdInfo) {}
LevelPlay Ad Info
The LPMAdInfo parameter includes information about the loaded ad.
Learn more about its implementation and available fields here.
Load Interstitial Ad
To load an interstitial ad use loadAd.
Show Interstitial Ad
Show an interstitial ad after you receive the didLoadAd callback.
- It is required to share ViewController.
- If using placements, pass the placement name in the showAd API as shown in the Placements section below.
- Once the ad has been successfully displayed to the user, you can load another ad by repeating the loading step.
- (void)showInterstitialAd {
// Check that ad is ready
if ([self.interstitialAd isAdReady]) {
// Show without placement
[self.interstitialAd showAdWithViewController:self placementName:NULL];
}
}
func showInterstitialAd() {
// Check that ad is ready
if self.interstitialAd.isAdReady() {
// Show without placement
self.interstitialAd.showAd(viewController: self, placementName: nil)
}
}
Check Ad is Ready
To avoid show failures, and to make sure the ad could be displayed correctly, we recommend using the following API before calling the showAd API.
isAdReady – returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.
isPlacementCapped – returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.
// Check that ad is ready and that the placement is not capped
if ([self.interstitialAd isAdReady] && ![LPMInterstitialAd isPlacementCapped:placementName]) {
[self.interstitialAd showAdWithViewController:self placementName:placementName];
}
// Check that ad is ready and that the placement is not capped
if self.interstitialAd.isAdReady(), !LPMInterstitialAd.isPlacementCapped(placementName) {
self.interstitialAd.showAd(viewController: self, placementName: placementName)
}
Placements
We support placements pacing and capping for interstitial on the LevelPlay dashboard.
If placements are set up for interstitial ads, call the showAd method to serve the ad for a specific placement.
// Check that ad is ready and that the placement is not capped
if ([self.interstitialAd isAdReady] && ![LPMInterstitialAd isPlacementCapped:placementName]) {
// Show ad with placement
[self.interstitialAd showAdWithViewController:self placementName:@"PlacementName"];
}
// Check that ad is ready and that the placement is not capped
if self.interstitialAd.isAdReady(), !LPMInterstitialAd.isPlacementCapped(placementName) {
// Show ad with placement
self.interstitialAd.showAd(viewController: self, placementName: placementName)
}
Full Implementation Example of Interstitial Ads
NS_ASSUME_NONNULL_BEGIN
@interface InterstitialAdViewController () <LPMInterstitialAdDelegate>
@property(nonatomic, strong) LPMInterstitialAd *interstitialAd;
@end
@implementation InterstitialAdViewController
- (void)createInterstitialAd {
self.interstitialAd = [[LPMInterstitialAd alloc] initWithAdUnitId:@"adUnitId"];
self.interstitialAd.delegate = self;
}
- (void)loadInterstitialAd {
// used to load or reload the ad
[self.interstitialAd loadAd];
}
- (void)showInterstitialAd {
if ([self.interstitialAd isAdReady]) {
[self.interstitialAd showAdWithViewController:self placementName:NULL];
}
}
- (void)showInterstitialAdWithPlacementName:(NSString *)placementName {
// check that ad is ready and that the placement is not capped
if ([self.interstitialAd isAdReady] && ![LPMInterstitialAd isPlacementCapped:placementName]) {
[self.interstitialAd showAdWithViewController:self placementName:placementName];
}
}
#pragma mark - LPMInterstitialAdDelegate Methods
- (void)didLoadAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didFailToLoadAdWithAdUnitId:(NSString *)adUnitId error:(NSError *)error {}
- (void)didChangeAdInfo:(LPMAdInfo *)adInfo {}
- (void)didDisplayAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didFailToDisplayAdWithAdInfo:(LPMAdInfo *)adInfo error:(NSError *)error {}
- (void)didClickAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didCloseAdWithAdInfo:(LPMAdInfo *)adInfo {}
@end
NS_ASSUME_NONNULL_END
class InterstitialAdViewController: UIViewController, LPMInterstitialAdDelegate {
var interstitialAd: LPMInterstitialAd!
func createInterstitialAd() {
self.interstitialAd = LPMInterstitialAd(adUnitId: "adUnitId")
self.interstitialAd.setDelegate(self)
}
func loadInterstitialAd() {
// used to load or reload the ad
self.interstitialAd.loadAd()
}
func showInterstitialAd() {
if self.interstitialAd.isAdReady() {
self.interstitialAd.showAd(viewController: self, placementName: nil)
}
}
func showInterstitialAd(withPlacementName placementName: String) {
// check that ad is ready and that the placement is not capped
if self.interstitialAd.isAdReady(), !LPMInterstitialAd.isPlacementCapped(placementName) {
self.interstitialAd.showAd(viewController: self, placementName: placementName)
}
}
// MARK: LPMInterstitialAdDelegate methods
func didLoadAd(with adInfo: LPMAdInfo) {}
func didFailToLoadAd(withAdUnitId adUnitId: String, error: Error) {}
func didChangeAdInfo(_ adInfo: LPMAdInfo) {}
func didDisplayAd(with adInfo: LPMAdInfo) {}
func didFailToDisplayAd(with adInfo: LPMAdInfo, error: Error) {}
func didClickAd(with adInfo: LPMAdInfo) {}
func didCloseAd(with adInfo: LPMAdInfo) {}
}
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate interstitial Ad Unit APIs in your app.
Done!
You are now all set up to serve banners in your application. Verify your integration with our Integration Test Suite.
Follow our integration guides to integrate additional Interstitial Ad networks or configure additional ad formats: