我们支持静态插页式广告和视频插页式广告。请按照以下说明设置插页式广告。
它IMInterstitial只是一个UIViewController子类,用于显示响应用户触摸的全屏广告。
请按照以下步骤以程序化方式创建插页式广告单元:
导入头文件并在ViewController.h / ViewController.swift文件中声明一个插值实例。你的ViewController头文件应该如下所示:
#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?
}
实例化间隙对象。文件viewDidLoad中的方法ViewController.m应该如下所示:
-(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 ID here>)
interstitial?.delegate = self
interstitial?.load()
}
对于广告状态回调,请实现代理方法IMInterstitialDelegate。以下是支持的回调:
// 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");
}
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)")
}
要显示插页式广告,请使用以下代码:
[self.interstitial showFrom:self];
[self.interstitial showFrom:self with:IMInterstitialAnimationTypeAsNone];
interstitial?.show(from: self)
//interstitial?.show(from: self, with:.coverVertical)
以下是可能的动画类型:
IMInterstitialAnimationTypeCoverVerticalIMInterstitialAnimationTypeFlipHorizontalIMInterstitialAnimationTypeAsNone重要的:
interstitialDidFinishLoading在调用之前已收到回调函数。否则,将返回showFromViewController错误回调函数。interstitial:didFailToPresentScreenWithError:[self.interstitial load];再次调用此功能。否则,您将无法showFromViewController再次调用。以下是可能的动画类型:
coverVerticalflipHorizontalNone重要的:
interstitialDidFinishLoading在调用之前已收到回调函数。否则,将返回show(from viewController: UIViewController!)错误回调函数。interstitial(_ interstitial: IMInterstitial!, didFailToLoadWithError error: IMRequestStatus!)interstitial?.load()再次调用此功能。否则,您将无法show(from viewController: UIViewController!)再次调用。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.
Support Center