Migrate to Interstitial Ad Unit API
This guide explains how to transition to the LevelPlay Interstitial APIs (using an ad unit ID) from your current implementation, to load and display interstitial ads.
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 instead of LevelPlayInterstitialDelegate 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) {}
Legacy | Ad Unit (new) | |
Delegates | LevelPlayInterstitialDelegate | LPMInterstitialAdDelegate |
Events | didLoadWithAdInfo | didLoadAdWithAdInfo |
didFailToLoadWithError | didFailToLoadAdWithAdUnitId | |
didOpenWithAdInfo | didDisplayAdWithAdInfo | |
didCloseWithAdInfo | didCloseAdWithAdInfo | |
didFailToShowWithError | didFailToDisplayAdWithAdInfo | |
didClickWithAdInfo | didClickAdWithAdInfo | |
didShowWithAdInfo | – (deprecated) | |
– | didChangeAdInfo |
LevelPlay Ad Info
The ISAdInfo class returned by the interstitial listener callbacks has been replaced by LPMAdInfo.
Learn more about its implementation and available fields here.
Load Interstitial Ad
To load a interstitial ad, use loadAd instead of loadInterstitial.
Show Interstitial Ad
Show an interstitial ad after you receive didLoadWithAdInfo callback, using the LPMInterstitialAdDelegate, instead of LevelPlayInterstitialDelegate. Use showAdWithViewController instead of showInterstitialWithViewController.
- 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)
}
Multiple Ad Unit Interstitial APIs
Legacy | Ad Unit (new) | |
API | loadInterstitial | loadAd |
showInterstitialWithViewController | showAdWithViewController | |
hasInterstitial | isAdReady | |
isInterstitialCappedForPlacement | isPlacementCapped |
Full Implementation Example of Ad Unit API
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 interstitial ads in your application using our new Multiple Ad Unit APIs.