Rewarded Ads Integration for iOS

The Unity LevelPlay Rewarded is a full-screen ad unit, usually served at natural transition points during the app lifecycle. 

Before you start
    • 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.5.0+. Documentation for legacy Rewarded APIs (SDK 8.5.0 and below) can be found here.

    Create Rewarded Ad Object

    The creation of the Rewarded ad object must be performed after receiving the onInitSuccess callback.

    The object is a reusable instance that can handle multiple loads and shows throughout the session. Once created, it should be used to load and show ads for the same ad unit.

    For more advanced implementations, you may create multiple Rewarded ad objects if necessary.

    self.rewardedAd = [[LPMRewardedAd alloc] initWithAdUnitId:@"adUnitId"];
    self.rewardedAd = LPMRewardedAd(adUnitId: "adUnitId")

    Implement Delegates

    Implement the LPMRewardedAdDelegate in your code to get informed of ad delivery. 

    • It is recommended to set the delegate before loading the Rewarded ad.
    • Please note that each Rewarded ad should have its own delegate implementation.
    • Delegate methods run on the main thread.
    self.rewardedAd = [[LPMRewardedAd alloc] initWithAdUnitId:@"adUnitId"]; 
    self.rewardedAd.delegate = self;
    
    #pragma mark - LPMRewardedAdDelegate 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 {}
    - (void)didRewardAdWithAdInfo:(LPMAdInfo *)adInfo reward:(LPMReward *)reward {}
    self.rewardedAd = LPMRewardedAd(adUnitId: "adUnitId") 
    self.rewardedAd.setDelegate(self)
      
    // MARK: LPMRewardedAdDelegate 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) {}
    func didRewardAd(with adInfo: LPMAdInfo, reward: LPMReward) {}

    LevelPlay Ad Info

    Ad Info

    The LPMAdInfo parameter includes information about the loaded ad.

    Learn more about its implementation and available fields here.

    Load Rewarded Ad

    To load an Rewarded ad use loadAd.

    [self.rewardedAd loadAd];
    self.rewardedAd.loadAd()

    Show Rewarded Ad

    Show an Rewarded 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)showRewardedAd {
        // Check that ad is ready
        if ([self.rewardedAd isAdReady]) {
            // Show without placement
            [self.rewardedAd showAdWithViewController:self placementName:NULL];
        }
    }
    func showRewardedAd() {
        // Check that ad is ready  
        if self.rewardedAd.isAdReady() {
            // Show without placement
            self.rewardedAd.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.rewardedAd isAdReady] && ![LPMRewardedAd isPlacementCapped:placementName]) {
        [self.rewardedAd showAdWithViewController:self placementName:placementName];
    }
    
    // Check that ad is ready and that the placement is not capped 
    if self.rewardedAd.isAdReady(), !LPMRewardedAd.isPlacementCapped(placementName) {
        self.rewardedAd.showAd(viewController: self, placementName: placementName)
    }

    Placements

    We support placements pacing and capping for Rewarded on the LevelPlay dashboard. 

    If placements are set up for Rewarded 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.rewardedAd isAdReady] && ![LPMRewardedAd isPlacementCapped:placementName]) {
        // Show ad with placement
        [self.rewardedAd showAdWithViewController:self placementName:@"PlacementName"];
    }
    // Check that ad is ready and that the placement is not capped 
    if self.rewardedAd.isAdReady(), !LPMRewardedAd.isPlacementCapped(placementName) {
        // Show ad with placement
        self.rewardedAd.showAd(viewController: self, placementName: placementName) 
    }

    Reward the User

    The LevelPlay SDK will fire the didRewardAd each time the user successfully completes a video.

    The didRewardAd and didCloseAd are asynchronous. Make sure to set up your listener to grant rewards even in cases where didRewardAd is fired after the didCloseAd.

    - (void)didRewardAdWithAdInfo:(LPMAdInfo *)adInfo reward:(LPMReward *)reward {
        // Implement logic to grant the reward to the user
        NSString *name = reward.name; 
        NSInteger *amount = reward.amount;
    }
    
    func didRewardAd(with adInfo: LPMAdInfo, reward: LPMReward) {
        // Implement logic to grant the reward to the user
        let name: String = reward.name 
        let amount: Int = reward.amount
    }
    

    Full Implementation Example of Rewarded Ads

    NS_ASSUME_NONNULL_BEGIN
    @interface RewardedAdViewController () <LPMRewardedAdDelegate>
    @property(nonatomic, strong) LPMRewardedAd *RewardedAd;
    @end
    @implementation RewardedAdViewController
    - (void)createRewardedAd {
        self.rewardedAd = [[LPMRewardedAd alloc] initWithAdUnitId:@"adUnitId"];
        self.rewardedAd.delegate = self;
    }
    - (void)loadRewardedAd {
        // used to load or reload the ad
        [self.rewardedAd loadAd];
    }
    - (void)showRewardedAd {
        if ([self.rewardedAd isAdReady]) {
            [self.rewardedAd showAdWithViewController:self placementName:NULL];
        }
    }
    - (void)showRewardedAdWithPlacementName:(NSString *)placementName {
        // check that ad is ready and that the placement is not capped 
        if ([self.rewardedAd isAdReady] && ![LPMRewardedAd isPlacementCapped:placementName]) {
            [self.rewardedAd showAdWithViewController:self placementName:placementName];
        }
    }
    #pragma mark - LPMRewardedAdDelegate 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 {}
    - (void)didRewardAdWithAdInfo:(LPMAdInfo *)adInfo reward:(LPMReward *)reward {} 
    @end
    NS_ASSUME_NONNULL_END
    class RewardedAdViewController: UIViewController, LPMRewardedAdDelegate {
        var RewardedAd: LPMRewardedAd!
        
        func createRewardedAd() {
            self.rewardedAd = LPMRewardedAd(adUnitId: "adUnitId")
            self.rewardedAd.setDelegate(self)
        }
        
        func loadRewardedAd() {
            // used to load or reload the ad
            self.rewardedAd.loadAd()
        }
        
        func showRewardedAd() {
            if self.rewardedAd.isAdReady() {
                self.rewardedAd.showAd(viewController: self, placementName: nil)
            }
        }
        
        func showRewardedAd(withPlacementName placementName: String) {
            // check that ad is ready and that the placement is not capped 
            if self.rewardedAd.isAdReady(), !LPMRewardedAd.isPlacementCapped(placementName) {
                self.rewardedAd.showAd(viewController: self, placementName: placementName)
            }
        }
        
        // MARK: LPMRewardedAdDelegate 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) {}
        func didRewardAd(with adInfo: LPMAdInfo, reward: LPMReward) {} 
    }

    LevelPlay Mediation Demo App

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

    Download iOS Demo Application

    Done!
    You are now all set up to serve banners in your application. Verify your integration with our Integration Test Suite.


    What’s Next?
    Follow our integration guides to integrate additional Rewarded Ad networks or configure additional ad formats: