Rewarded ads integration for iOS
Implement the Rewarded Video ad unit in your iOS app by initializing the ad unit, setting delegates, and handling ad events.
Read time 4 minutesLast updated 4 hours ago
The Unity LevelPlay Rewarded is a full-screen ad unit, usually served at natural transition points during the app lifecycle.
Prerequisites
- Ensure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.
- Ensure that you initialize the SDK using LevelPlay Initialization API.
- Find the AdUnitID in LevelPlay dashboard.
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. After creation, it should be used to load and show ads for the same ad unit. For more advanced implementations, you can create multiple Rewarded ad objects if necessary.self.rewardedAd = [[LPMRewardedAd alloc] initWithAdUnitId:@"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.
- 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 {}
LevelPlay Ad Info
The LPMAdInfo parameter includes information about the loaded ad.Load Rewarded Ad
To load a Rewarded ad use loadAd.[self.rewardedAd loadAd];
Show Rewarded Ad
Show a 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.
- After 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]; } }
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]; }
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"]; }
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; }
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