Rewarded Video Ads

Set up a Rewarded Video Ad

After adding your app, select REWARDED VIDEO to create a placement for ad type Rewarded video.

Once you select the placement type as rewarded video, you will be presented with the following.

You can fill in the key value pair for reward details. SDK will provide this dictionary as a JSON string through a delegate method called interstitial:rewardActionCompletedWithRewards: when the video play has ended. You can also choose to handle these rewards completely at your end.


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 property of IMInterstitial. The following callbacks are supported:

    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

    /** 
    * Notifies the delegate that the ad server has returned an ad. Assets are not yet available. 
    * Please use interstitialDidFinishLoading: to receive a callback when assets are also available. 
    */ 
    public func interstitialDidReceiveAd(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitialDidFinishLoading(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitial(_ interstitial: IMInterstitial!, didFailToLoadWithError error: IMRequestStatus!) { 
        NSLog("[ViewController %@]", #function) 
        NSLog("Interstitial ad failed to load with error %@", error) 
    } 
    public func interstitialWillPresent(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitialDidPresent(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitial(_ interstitial: IMInterstitial!, didFailToPresentWithError error: IMRequestStatus!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitialWillDismiss(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitialDidDismiss(_ interstitial: IMInterstitial!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitial(_ interstitial: IMInterstitial!, didInteractWithParams params: [AnyHashable : Any]!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func interstitial(_ interstitial: IMInterstitial!, rewardActionCompletedWithRewards rewards: [AnyHashable : Any]!) { 
        NSLog("[ViewController %@]", #function) 
    } 
    public func userWillLeaveApplication(from interstitial: IMInterstitial!){ 
        NSLog"[ViewController %@]", #function) 
    }
    
  4. To show the Interstitial ad, use the following code:
     

    Objective C

    [self.interstitial showFromViewController:self];
    //[self.interstitial showFromViewController:self withAnimation:kIMInterstitialAnimationTypeCoverVertical];
    

    Swift

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

 

Objective C

Here are the possible animation types:

  • kIMInterstitialAnimationTypeCoverVertical
  • kIMInterstitialAnimationTypeFlipHorizontal
  • kIMInterstitialAnimationTypeNone


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: 14 Oct, 2020