Rewarded Video Ads Integration for iOS

Do go through the steps in our Getting Started Guide to add Media.Net SDK to your project before starting the integration of Rewarded Video Ads.

For adding rewarded video ads to your app, following are the steps:

  • Import the required headers
  • Define an ad slot
  • Set up delegates

Step 1: Import the required headers at the top of the file -

Use the below mentioned line to import the headers

Objective-C

@import MNetAdSdk;

Swift

import MNetAdSdk

Or, you can add the headers individually using the below listed lines

#import <MNAdSdk/MNet.h>
#import <MNetAdSdk/MNetRewardedVideo.h>
#import <MNetAdSdk/MNetReward.h>
#import <MNAdSdk/MNetError.h>

Step 2: Defining an ad slot and loading an ad.

The integration of rewarded video ad to your app can be done as the below example.

Objective-C

// DEMO_MN_AD_UNIT_ID is the ad unit id
// Create an instance of MNetRewardedVideo

MNetRewardedVideo *rewardedVideo = [MNetRewardedVideo getInstanceForAdUnitId : DEMO_MN_AD_UNIT_REWARDED];
[rewardedVideo setRewardedVideoDelegate:self];
[rewardedVideo setKeywords:@"bugs, bunny"];
[rewardedVideo setRewardWithName : @"NEW_REWARD" forCurrency :@"INR" forAmount : 100];
[rewardedVideo loadRewardedAd];

Swift

let rewardedAdView = MNetRewardedVideo.getInstanceForAdUnitId(DemoConstants.DEMO_MN_AD_UNIT_REWARDED)
rewardedAdView.rewardedVideoDelegate = self
rewardedAdView.setRewardWithName("NEW_REWARD!", forCurrency: "INR", forAmount: 100000)
rewardedAdView.keywords = "bugs, bunny"
rewardedAdView.loadRewardedAd()

Note:

MNetRewardedVideo is similar to how MNetInterstialAd works. The rewarded video can be shown using - showAdFromViewController: on the MNetRewardedVideo object, which needs to be called after the ad is loaded (in the rewardedVideoDidLoad callback). The example below illustrates that -

Objective-C

- (void)rewardedVideoDidLoad:(MNetRewardedVideo *)rewardedVideo {
    [rewardedVideo showAdFromViewController:self];
}

Swift

func mnetRewardedVideoDidLoad(_ rewardedVideo: MNetRewardedVideo) {
    rewardedVideo.showAd(from: self);
}

Step 3: Setting up Delegates

You can listen to the following important delegates in MNetRewardedVideoDelegate -

@optional

/// Callback when the rewarded video started
- (void)mnetRewardedVideoDidStart:(MNetRewardedVideo *)rewardedVideo;

/// Callback when the rewared video has completed.
/// This returns the reward object that is set init
- (void)mnetRewardedVideoDidComplete:(MNetRewardedVideo *)rewardedVideo withReward:(MNetReward *)reward;

/// Callback when the rewarded video has completed loading
- (void)mnetRewardedVideoDidLoad:(MNetRewardedVideo *)rewardedVideo;

/// Callback when the rewarded video failed to load
- (void)mnetRewardedVideoDidFailToLoad:(MNetRewardedVideo *)rewardedVideo withError:(MNetError *)error;

/// Callback when the rewarded video is clicked
- (void)mnetRewardedVideoDidClick:(MNetRewardedVideo *)rewardedVideo;

/// Callback when the rewarded video is shown
- (void)mnetRewardedVideoDidShow:(MNetRewardedVideo *)rewardedVideo;

Note:

The rewardedVideDidCompleted:withReward: reward dispenses the reward that’s been set by ` setRewardWithName:forCurrency:forAmount:` when making the ad request.