AI Search

激励视频广告

设置激励视频广告

  1. 从左侧导航栏选择“库存” >“库存设置”
  2. 搜索您想要为其创建广告位的应用或网站,然后点击+ 添加广告位
  3. 点击“选择广告单元”,然后选择“激励视频”
  4. 点击“添加广告位”开始设置激励视频广告。创建激励视频广告位后,即可查看广告位 ID。

将激励视频广告添加到您的应用

创建激励视频广告

激励视频广告使用 IMInterstitial 类。该类IMInterstitial是一个UIViewController子类,用于显示响应用户触摸的全屏广告。

按照以下步骤,通过程序化方式创建激励视频广告单元:

  1. 导入头文件并在根目录中声明一个插页式实例ViewController.h 。ViewController.swift您的ViewController头文件应如下所示:

    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. 实例化插页式广告对象。每个广告位 ID 只创建一个对象,并在后续广告加载时重复使用。文件 viewDidLoad 中的方法ViewController.m应如下所示:

    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. 对于广告状态回调,请实现代理方法IMInterstitialDelegate。以下是支持的回调:

    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. 要显示插页式广告,请使用以下代码:

    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

以下是可能的动画类型:

  • IMInterstitialAnimationTypeCoverVertical
  • IMInterstitialAnimationTypeFlipHorizontal
  • IMInterstitialAnimationTypeAsNone

重要的

  • 确保interstitialDidFinishLoading在调用 `show()` 之前触发委托showFromViewController。否则,会触发错误回调interstitial:didFailToPresentScreenWithError:。持续监听插页式广告状态,仅在广告完全加载后才调用 `show()`。
  • 每次插页式广告显示后被关闭,您都需要[self.interstitial load];再次调用此功能。否则,您将无法showFromViewController再次调用。
  • 实现检测视频播放完成interstitial:rewardActionCompletedWithRewards:的方法。如果您已在 InMobi 门户网站上设置了奖励,则可以在此处访问 JSON 字典。IMInterstitialDelegate

Swift

以下是可能的动画类型:

  • coverVertical
  • flipHorizontal
  • none

重要的

  • 确保interstitialDidFinishLoading在调用 `show()` 之前触发委托show(from viewController: UIViewController!)。否则,会触发错误回调interstitial(_ interstitial: IMInterstitial!, didFailToLoadWithError error: IMRequestStatus!)。持续监听插页式广告状态,仅在广告完全加载后才调用 `show()`。
  • 每次插页式广告显示后被关闭,您都需要interstitial?.load()再次调用此功能。否则,您将无法show(from viewController: UIViewController!)再次调用。
  • 实现检测视频播放完成interstitial(_ interstitial: IMInterstitial!, rewardActionCompletedWithRewards rewards: [AnyHashable : Any]!)的方法。如果您已在 InMobi 门户网站上设置了奖励,则可以在此处访问 JSON 字典。IMInterstitialDelegate

本页内容

最后更新于 : 10 Sep, 2026