Migrate to Banner Ad Units API

This guide explains how to integrate the LevelPlay APIs using an ad unit ID to load and display banner ads.

⚡ Before you start
  • The min supported SDK is 8.6.0. You can download the latest SDK here.
  • Make sure to initalize the SDK using LevelPlay Initalization API. Learn more here.
  • You can find the AdUnitID in LevelPlay dashboard. Learn more here.

Create Banner Ad Object and Set Size

The creation of the banner ad object should be done after receiving onInitSuccess callback.

// Create the banner view and set the ad unit id 
self.bannerAdView = [[LPMBannerAdView alloc] initWithAdUnitId:@"adUnitId"];
  • Light theme
  • Dark theme
  • Copy to clipboard
Legacy Ad Unit (new) Dimensions in dp
ISBannerSize LPMAdSize (Width X Height)
ISBannerSize_BANNER bannerSize 320 x 50
ISBannerSize_LARGE largeSize 320 x 90
ISBannerSize_RECTANGLE mediumRectangleSize 300 x 250
ISBannerSize_SMART Replaced by Adaptive Ad Size (see below) Automatically renders ads to adjust size and orientation for mobile & tablets

To create the ad size follow one of these options: 

Adaptive ad size that adjusts to the screen width (recommended):

This option returns BANNER or LEADERBOARD according to the device type.
Networks that supports adaptive feature (Google, Yandex) will return the a height based on their optimization logic.

LPMAdSize *bannerSize = [LPMAdSize createAdaptiveAdSize];
[self.bannerAdView setAdSize: bannerSize];
  • Light theme
  • Dark theme
  • Copy to clipboard

Specific banner size:
This option allows you to set specifically a banner size: BANNER, LARGE, MEDIUM_RECTANGLE.

LPMAdSize *bannerSize = [LPMAdSize largeSize];
[self.bannerAdView setAdSize: bannerSize];
  • Light theme
  • Dark theme
  • Copy to clipboard

Placements

We support placements in banners for reporting only. Placements should be set before the loadAd, to affect all reloaded ads.

// Set the placement name
[self.bannerAdView setPlacementName:@"PlacementName"];
  • Light theme
  • Dark theme
  • Copy to clipboard

Set Banner Delegates 

Implement the LPMBannerAdViewDelegate instead of LevelPlayBannerDelegate in your code to get informed of ad delivery. 

  • It is recommended to set the delegates before loading the banner ad.
  • Please note that each banner ad view should have its own delegate implementation.
  • Callbacks run on the main thread.
// Set delegate implementation 
[self.bannerAdView setDelegate:self]
#pragma mark - LPMBannerAdViewDelegate
- (void)didLoadAdWithAdInfo:(nonnull LPMAdInfo *)adInfo {
   //Ad was loaded successfully
}
- (void)didFailToLoadAdWithAdUnitId:(nonnull NSString *)adUnitId error:(nonnull NSError *)error { 
   // Ad load failed
}
- (void)didClickAdWithAdInfo:(LPMAdInfo *)adInfo {
   // Ad was clicked
}
- (void)didDisplayAdWithAdInfo:(LPMAdInfo *)adInfo {
   // Ad was displayed and visible on screen
}
- (void)didFailToDisplayAdWithAdInfo:(LPMAdInfo *)adInfo error:(NSError *)error {
   // Ad was failed to be displayed on screen
}
- (void)didLeaveAppWithAdInfo:(LPMAdInfo *)adInfo {
   // User pressed on the ad and was navigated out of the app 
}
- (void)didExpandAdWithAdInfo:(LPMAdInfo *)adInfo {
   // Ad is opened on full screen
}
- (void)didCollapseAdWithAdInfo:(LPMAdInfo *)adInfo {
   // Ad is restored to its original size
}
  • Light theme
  • Dark theme
  • Copy to clipboard

LevelPlay Ad Info

Ad Info

The LevelPlayAdInfo parameter includes information about the loaded ad.

Learn more about its implementation and available fields here.

IronSource Legacy API Ad Unit API
Delegates LevelPlayBannerDelegate LPMBannerAdViewDelegate
Events didLoad didLoadAdWithAdInfo
didFailToLoadWithError didFailToLoadAdWithAdUnitId
didClickWithAdInfo didClickAdWithAdInfo
didPresentScreenWithAdInfo didExpandAdWithAdInfo
didDismissScreenWithAdInfo didCollapseAdWithAdInfo
didLeaveApplicationWithAdInfo didLeaveAppWithAdInfo
didDisplayAdWithAdInfo
didFailToDisplayAdWithAdInfo

Load Banner Ad

To load a banner ad, use loadAd instead of IronSource.loadBanner.

// Load the banner ad
[self.bannerAdView loadAdWithViewController:self]
  • Light theme
  • Dark theme
  • Copy to clipboard

Pause and Resume Banner Refresh 

You can pause banner refresh in your code if the refresh value was defined in the platform. Use the following methods to stop the automatic refresh of the banner ad, or re-enable it after pausing. 

Note:

When the banner is displayed again, it will complete the time till refresh, from the time it was paused. 

  • pauseAutoRefresh – pauses auto-refresh of the banner ad.
  • resumeAutoRefresh – resumes auto-refresh of the banner ad after it has been paused.
// Pause refresh
[self.bannerAdView pauseAutoRefresh]; 
// Resume refresh
[self.bannerAdView resumeAutoRefresh];
  • Light theme
  • Dark theme
  • Copy to clipboard

Destroy Banner Ad

To destroy a banner, call the destroy method.

A destroyed banner can no longer be shown again. To display more ads, create a new LPMBannerAdView object.

[self.bannerAdView destroy];
  • Light theme
  • Dark theme
  • Copy to clipboard

Multiple Ad Unit Banner APIs

Legacy Ad Unit (new)
Banner Ad View ISBannerView LPMBannerAdView
API loadBannerWithViewController loadAdWithViewController
loadBannerWithViewController setPlacementName
destroyBanner destroy
LPMAdSize.width
LPMAdSize.height
pauseAutoRefresh
resumeAutoRefresh

Full Implementation Example of Banner Ads

Here is an example for creating and loading a banner ad using adaptive banner size.

NS_ASSUME_NONNULL_BEGIN
@interface BannerAdViewController () <LPMBannerAdViewDelegate>
@property(nonatomic, strong) LPMBannerAdView *bannerAd;
@end
@implementation BannerAdViewController
- (void)dealloc {
    [self.bannerAd destroy];
}
- (void)createBannerAd {
    // Create the banner view and set the ad unit id
    self.bannerAd = [[LPMBannerAdView alloc] initWithAdUnitId:@"adUnitId"];
    
    // Set the placement name (optional)
    [self.bannerAd setPlacementName:@"PlacementName"];
    
    // Set the ad size
    LPMAdSize *bannerSize = [self getBannerSize];
    
    // Required when using adaptive ad size
    if (bannerSize == nil) {
        return;
     }
    
    [self.bannerAd setAdSize:bannerSize];
    
    // Set the delegate implementation
    [self.bannerAd setDelegate:self];
    
    // Add the banner view to the view hierarchy with the proper constraints
    [self addBannerViewWithSize:bannerSize];
}
- (LPMAdSize *)getBannerSize {
    // 1. Recommended - Adaptive ad size that adjusts to the screen width
    LPMAdSize *bannerSize = [LPMAdSize createAdaptiveAdSize];
    // 2. Adaptive ad size using fixed width ad size
    // self.bannerSize = [LPMAdSize createAdaptiveAdSizeWithWidth:400];
    // 3. Specific banner size - BANNER, LARGE, MEDIUM_RECTANGLE
    // self.bannerSize = [LPMAdSize mediumRectangleSize];
    
    return bannerSize;
}
- (void)loadBannerAd {
    [self.bannerAd loadAdWithViewController:self];
}
- (void)addBannerViewWithSize:(LPMAdSize *)bannerSize {
    self.bannerAd.translatesAutoresizingMaskIntoConstraints = NO;
    
    // Add the banner view to the view hierarchy
    [self.view addSubview:self.bannerAd];
    [NSLayoutConstraint activateConstraints:@[
        [self.bannerAd.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
        [self.bannerAd.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
        [self.bannerAd.widthAnchor constraintEqualToConstant:bannerSize.width],
        [self.bannerAd.heightAnchor constraintEqualToConstant:bannerSize.height]
    ]];
}
#pragma mark - LPMBannerAdViewDelegate
- (void)didLoadAdWithAdInfo:(nonnull LPMAdInfo *)adInfo {}
- (void)didFailToLoadAdWithAdUnitId:(nonnull NSString *)adUnitId error:(nonnull NSError *)error {}
- (void)didClickAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didDisplayAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didFailToDisplayAdWithAdInfo:(LPMAdInfo *)adInfo error:(NSError *)error {}
- (void)didLeaveAppWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didExpandAdWithAdInfo:(LPMAdInfo *)adInfo {}
- (void)didCollapseAdWithAdInfo:(LPMAdInfo *)adInfo {}
@end
NS_ASSUME_NONNULL_END
  • Light theme
  • Dark theme
  • Copy to clipboard

LevelPlay Mediation Demo App

The Integration Demo application demonstrates how to integrate banner Ad Unit APIs in your app.

Download iOS Demo Application

Done!

You are now all set up to serve banner ads in your application using our new Multiple Ad Unit APIs.