Interstitial 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 Interstitial Video Ads.

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

@import MNetAdSdk;

or you can add the headers individually -

#import <MNAdSdk/MNet.h>
#import <MNAdSdk/MNetInterstitialAd.h>
#import <MNAdSdk/MNetError.h>

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

To integrate an interstitial-ad, it is recommended that you have a non-local reference to the MNetInterstitialAd instance, so that it is not deallocated immediately after loadAd method is called. In the examples below, this is achieved by adding MNetInterstitialAd as a property to the sample-view-controller. Note that it would be suffice to make it an instance-variable as well.

The following code-block illustrates loading of an interstitial-ad.

// In the SampleViewController.h file
@interface SampleViewController : UIViewController<MNetInterstitialAdDelegate>
@property (nonatomic) MNetInterstitialAd *interstitialAd;
@end

// In the SampleViewController.m file
@implementation SampleViewController

/// Loads interstitial-ad
- (void)loadInterstitialAd{
    // DEMO_MN_AD_UNIT_ID is the ad unit id
    // Create an instance of MNetInterstitialAd
    self.interstitialAd = [[MNetInterstitialAd alloc] initWithAdUnitId:
    DEMO_MN_AD_UNIT_ID];
    
    // set interstitialVideoDelegate for listening to events
    [self.interstitialAd setInterstitialVideoDelegate:self]; 

    // Optionally, the context-link can also be provided
    [self.interstitialAd setContextLink:@"https://my-context-link.com"];

    // Load the ad
    [self.interstitialAd loadAd];
}
@end

Swift

class AdsDisplayViewController: UIViewController, MNetInterstitialAdDelegate{
    var interstitialAdView:MNetInterstitialAd?

    /// Loads interstitial-ad
    func loadInterstitialAd(){
        self.interstitialAdView = MNetInterstitialAd.init(adUnitId: DemoConstants.DEMO_INTERSTITIAL_AD_UNIT)

        // set interstitialVideoDelegate for listening to events
        self.interstitialAdView.interstitialVideoDelegate = self

        // Optionally, the context-link can also be provided
        self.interstitialAdView.setContextLink("http://my-context-link")

        // Load the ad
        self.interstitialAdView.load()
    }
}

The setContextLink is an optional API on the adviews which allows the developers to provide a contextual link to the SDK.

Note:

  • MNetInterstialAd works differently from Banner Ad, it does not directly display the ad as soon it is loaded. The method - showAdFromViewController: on the MNetInterstitialAd object needs to be called after the ad is loaded, to display the ad.

  • To display the ad, you need to use the MNetInterstitialVideoAdDelegate protocol and implement the interstitialVideoAdDidLoad method. For example -

    -(void) interstitialVideoAdDidLoad:(MNetInterstitialAd *)interstitialAd {
      [interstitialAd showAdFromViewController:self];
    }
    

Swift

func mnetInterstitialVideoAdDidLoad(_ interstitialAd: MNetInterstitialAd) {
    interstitialAd.show(from: self)
}

Step 3: Setting up Delegates

You can listen to the following important delegates in MNetInterstitialVideoAdDelegate -

@optional

/// Callback when the video ad has loaded
- (void)mnetInterstitialVideoDidLoad:(MNetInterstitialAd *)interstitialAd;

/// Callback when the video ad failed to load
- (void)mnetInterstitialVideoDidFailToLoad:(MNetInterstitialAd *)interstitialAd withError:(MNetError *)error;

/// Callback when the video ad finished playing the video
- (void)mnetInterstitialVideoDidComplete:(MNetInterstitialAd *)interstitialAd;

/// Callback when the video starts playing
- (void)mnetInterstitialVideoDidStart:(MNetInterstitialAd *)interstitialAd;

/// Callback when the video ad is clicked
- (void)mnetInterstitialVideoDidClick:(MNetInterstitialAd *)interstitialAd;

/// Callback when the video ad is shown
- (void)mnetInterstitialVideoDidShow:(MNetInterstitialAd *)interstitialAd;

/// Callback when the interstitial ad is dismissed
- (void)mnetInterstitialVideoDidDismiss:(MNetInterstitialAd *)interstitialAd;