Rewarded Video Ads

Set up a Rewarded Video Ad

  1. From the left navigation select Inventory Inventory Settings.
  2. Search for the app or website you would like to create a placement for and click + Add a placement.
  3. Click Select Ad Unit and select Rewarded Video.
  4. Click Add a placement to start setting up your rewarded video settings. After you create the rewarded video placement, you can see the placement ID.


Add the Rewarded Video Ad to your App

Creating a Rewarded Video Ad

Rewarded Video ads use IMInterstitial Class. The IMInterstitial is simply a UIViewController subclass displaying full screen ads that respond to user touch.

Follow these steps to create the rewarded video ad unit programmatically:

  1. Import the headers and declare an interstitial instance in your ViewController.h / ViewController.swift file. Your ViewController header file should look like this:

    Objective-C

    #import  <UIKit/UIKit.h> 
    @import InMobiSDK; 
    @interface ViewController : UIViewController <IMInterstitialDelegate> 
    @property (nonatomic, strong) IMInterstitial *interstitial; 
    @end
    

    Swift

    import UIKit 
    import InMobiSDK 
    class ViewController: UIViewController, IMInterstitialDelegate { 
        var interstitial: IMInterstitial? 
    }
    
  2. Instantiate the interstitial object. Create only one object per placement ID and reuse it for subsequent ad loads. Your viewDidLoad method in ViewController.m file should look like this:


    Objective-C

    -(void)viewDidLoad { 
        [super viewDidLoad]; 
        self. interstitial = [[IMInterstitial alloc] initWithPlacementId:<Insert your placement ID here>]; 
        self. interstitial.delegate = self; 
        [self.interstitial load]; 
    }
    

    Swift

    override func viewDidLoad() { 
        super.viewDidLoad() 
        interstitial = IMInterstitial.init(placementId: <Insert your placement here.>) 
        interstitial?.delegate = self 
        interstitial?.load() 
    }
    
  3. For ad status callbacks, implement the delegate methods of IMInterstitialDelegate. Here are the supported callbacks:

    Objective-C

    - (void)interstitialDidFinishLoading:(IMInterstitial *)interstitial { 
        NSLog(@"interstitialDidFinishLoading"); 
    } 
    - (void)interstitial:(IMInterstitial *)interstitial didFailToLoadWithError:
    (IMRequestStatus *)error { 
        NSLog(@"Interstitial failed to load ad"); 
        NSLog(@"Error : %@",error.description); 
    } 
    - (void)interstitial:(IMInterstitial *)interstitial didFailToPresentWithError:
    (IMRequestStatus *)error { 
        NSLog(@"Interstitial didFailToPresentWithError"); 
        NSLog(@"Error : %@",error.description); 
    } 
    - (void)interstitialWillPresent:(IMInterstitial *)interstitial { 
        NSLog(@"interstitialWillPresent"); 
    } 
    - (void)interstitialDidPresent:(IMInterstitial *)interstitial { 
        NSLog(@"interstitialDidPresent"); 
    } 
    - (void)interstitialWillDismiss:(IMInterstitial *)interstitial { 
        NSLog(@"interstitialWillDismiss"); 
    } 
    - (void)interstitialDidDismiss:(IMInterstitial *)interstitial { 
        NSLog(@"interstitialDidDismiss"); 
    } 
    - (void)userWillLeaveApplicationFromInterstitial:(IMInterstitial *)interstitial { 
        NSLog(@"userWillLeaveApplicationFromInterstitial"); 
    } 
    - (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRewards:
    (NSDictionary *)rewards { 
        NSLog(@"rewardActionCompletedWithRewards"); 
    } 
    - (void)interstitial:(IMInterstitial *)interstitial didInteractWithParams:(NSDictionary *)params { 
        NSLog(@"InterstitialDidInteractWithParams"); 
    } 
    / * Not used for direct integration. Notifies the delegate that the ad server has returned an ad but assets are not yet available. */ 
    - (void)interstitialDidReceiveAd:(IMInterstitial *)interstitial { 
      NSLog(@"interstitialDidReceiveAd"); 
    }
    

    Swift

    public func interstitialDidReceiveAd(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitialDidFinishLoading(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitial(_ interstitial: IMInterstitial, didFailToLoadWithError error: IMRequestStatus) {
            print("[ViewController %@] \(#function)")
            print("Interstitial ad failed to load with error \(error)" )
        }
        public func interstitialWillPresent(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitialDidPresent(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitial(_ interstitial: IMInterstitial, didFailToPresentWithError error: IMRequestStatus) {
            print("[ViewController %@] \(#function)")
            print("Interstitial ad failed to present with error \(error)" )
        }
        public func interstitialWillDismiss(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitialDidDismiss(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitial(_ interstitial: IMInterstitial, didInteractWithParams params: [String : Any]?) {
            print("[ViewController %@] \(#function)")
        }
        public func interstitial(_ interstitial: IMInterstitial, rewardActionCompletedWithRewards rewards: [String : Any]) {
            print("[ViewController %@] \(#function)")
        }
        public func userWillLeaveApplicationFromInterstitial(_ interstitial: IMInterstitial) {
            print("[ViewController %@] \(#function)")
        }
    
  4. To show the Interstitial ad, use the following code:

    Objective-C

    [self.interstitial showFrom:self];
    [self.interstitial showFrom:self with:IMInterstitialAnimationTypeAsNone];
    

    Swift

    interstitial?.show(from: self)
    //interstitial?.show(from: self, with:.coverVertical)
    	

Objective-C

Here are the possible animation types:

  • IMInterstitialAnimationTypeCoverVertical
  • IMInterstitialAnimationTypeFlipHorizontal
  • IMInterstitialAnimationTypeAsNone

Important

  • Make sure that interstitialDidFinishLoading delegate is fired before making a call to showFromViewController. Otherwise, the error callback interstitial:didFailToPresentScreenWithError: will be fired. Keep listening to the interstitial states to call show only when the ad is fully loaded.
  • Every time an interstitial ad is shown and subsequently dismissed, you will need to invoke [self.interstitial load]; again. Without this, you won't be able to call showFromViewController again.
  • Implement the interstitial:rewardActionCompletedWithRewards: method of IMInterstitialDelegate to detect video completion. If you have specified rewards on the InMobi portal, you can access the JSON dictionary here.

Swift

Here are the possible animation types:

  • coverVertical
  • flipHorizontal
  • none

Important

  • Make sure that interstitialDidFinishLoading delegate is fired before making a call to show(from viewController: UIViewController!). Otherwise, the error callback interstitial(_ interstitial: IMInterstitial!, didFailToLoadWithError error: IMRequestStatus!) will be fired. Keep listening to the interstitial states to call show only when the ad is fully loaded.
  • Every time an interstitial ad is shown and subsequently dismissed, you will need to invoke interstitial?.load() again. Without this, you won't be able to call show(from viewController: UIViewController!) again.
  • Implement the interstitial(_ interstitial: IMInterstitial!, rewardActionCompletedWithRewards rewards: [AnyHashable : Any]!) method of IMInterstitialDelegate to detect video completion. If you have specified rewards on the InMobi portal, you can access the JSON dictionary here.

On This Page

Last Updated on: 07 Jun, 2023