AI Search

插页式广告

我们支持静态插页式广告和视频插页式广告。请按照以下说明设置插页式广告。

设置插页式广告

  1. 从左侧导航栏中选择“库存” >“库存设置”。
  2. 搜索您想要为其创建广告位的应用或网站,然后点击+ 添加广告位
  3. 点击“选择广告单元”,然后选择“插页式广告”
  4. 点击“添加植入位置”开始设置您的插膜设置。创建插膜植入位置后,您可以看到植入位置 ID。

     

在您的应用中添加插页式广告

创建插页式广告

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. 实例化间隙对象。文件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 ID here>) 
        interstitial?.delegate = self 
        interstitial?.load() 
    } 
    
  3. 对于广告状态回调,请实现代理方法IMInterstitialDelegate。以下是支持的回调:

    Objective C

    // Notifies that the ad is received with Meta info. 
    - (void)interstitial:(IMInterstitial *)interstitial didReceiveWithMetaInfo:(IMAdsMetaInfo*)metaInfo { 
        NSLog(@"interstitial didReceiveAdWithMetaInfo"); 
    } 
    - (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 didInteractWithParams:
    (NSDictionary *)params { 
        NSLog(@"InterstitialDidInteractWithParams"); 
    }
    

    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在调用之前已收到回调函数。否则,将返回showFromViewController错误回调函数。interstitial:didFailToPresentScreenWithError:
  • 每次插页式广告显示后被关闭,您都需要[self.interstitial load];再次调用此功能。否则,您将无法showFromViewController再次调用。

Swift

以下是可能的动画类型:

  • coverVertical
  • flipHorizontal
  • None

重要的:

  • 请确保interstitialDidFinishLoading在调用之前已收到回调函数。否则,将返回show(from viewController: UIViewController!)错误回调函数。interstitial(_ interstitial: IMInterstitial!, didFailToLoadWithError error: IMRequestStatus!)
  • 每次插页式广告显示后被关闭,您都需要interstitial?.load()再次调用此功能。否则,您将无法show(from viewController: UIViewController!)再次调用。

本页内容

最后更新于 : 10 Sep, 2026