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:
Import the headers and declare an interstitial instance in your ViewController.h
/ ViewController.swift
file. Your ViewController
header file should look like this:
#import <UIKit/UIKit.h>
@import InMobiSDK;
@interface ViewController : UIViewController <IMInterstitialDelegate>
@property (nonatomic, strong) IMInterstitial *interstitial;
@end
import UIKit
import InMobiSDK
class ViewController: UIViewController, IMInterstitialDelegate {
var interstitial: IMInterstitial?
}
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:
-(void)viewDidLoad {
[super viewDidLoad];
self. interstitial = [[IMInterstitial alloc] initWithPlacementId:<Insert your placement ID here>];
self. interstitial.delegate = self;
[self.interstitial load];
}
override func viewDidLoad() {
super.viewDidLoad()
interstitial = IMInterstitial.init(placementId: <Insert your placement here.>)
interstitial?.delegate = self
interstitial?.load()
}
For ad status callbacks, implement the delegate methods of IMInterstitialDelegate
. Here are the supported callbacks:
- (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");
}
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)")
}
To show the Interstitial ad, use the following code:
[self.interstitial showFrom:self];
[self.interstitial showFrom:self with:IMInterstitialAnimationTypeAsNone];
interstitial?.show(from: self)
//interstitial?.show(from: self, with:.coverVertical)
Here are the possible animation types:
IMInterstitialAnimationTypeCoverVertical
IMInterstitialAnimationTypeFlipHorizontal
IMInterstitialAnimationTypeAsNone
Important
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.[self.interstitial load];
again. Without this, you won't be able to call showFromViewController
again.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.Here are the possible animation types:
coverVertical
flipHorizontal
none
Important
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.interstitial?.load()
again. Without this, you won't be able to call show(from viewController: UIViewController!)
again.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.By installing this SDK update, you agree that your Children Privacy Compliance setting remains accurate or that you will update that setting, whenever there is a change in your app's audience. You may update the app's Children Privacy Compliance settings at https://publisher.inmobi.com/my-inventory/app-and-placements.