优酷定制 SDK 插屏广告
适用于本仓库 SDK 6.5.1。API 以所安装版本的 framework 公开头为准。
先完成隐私与请求配置。下面使用普通请求;如需指定参数,可用该指南中的配置替换默认 IFLYAdRequestConfig。
#import <IFLYADLib/IFLYADLib.h>
@interface InterstitialViewController () <IFLYInterstitialAdDelegate>
@property (nonatomic, strong) IFLYInterstitialAd *interstitialAd;
@end
- (void)loadInterstitial {
IFLYInterstitialAd *ad = [[IFLYInterstitialAd alloc] initWithAdUnitId:@"YOUR_INTERSTITIAL_AD_UNIT_ID"];
ad.delegate = self;
ad.currentViewController = self;
self.interstitialAd = ad;
[ad loadAdWithRequestConfig:[[IFLYAdRequestConfig alloc] init]];
}
- (void)interstitialAdDidReady:(IFLYInterstitialAd *)ad {
if (ad != self.interstitialAd || !ad.isAdValid || !self.view.window) return;
IFLYInterstitialAdConfig *config = [[IFLYInterstitialAdConfig alloc] init];
config.presentationStyle = IFLYInterstitialPresentationStyleHalfScreen;
config.muteOnStart = YES;
[ad showAdFromRootViewController:self config:config];
}
- (void)interstitialAd:(IFLYInterstitialAd *)ad didFailWithError:(IFLYAdError *)error {
NSLog(@"Interstitial failed: %d %@", error.errorCode, error.errorDescription);
}可选 IFLYInterstitialPresentationStyleHalfScreen 或 IFLYInterstitialPresentationStyleFullScreen。素材横竖方向由返回素材决定,半屏/全屏由展示配置决定。请在当前页面可呈现时展示,避免与其他模态页面同时弹出;如果就绪回调到达时暂不可展示,可在后续业务时机重新检查 isAdValid。
interstitialAdDidLoad: 表示数据返回,interstitialAdDidReady: 表示素材准备完成。展示后关注 interstitialAdDidShow:、interstitialAdDidRender:、interstitialAdDidExpose: 和 interstitialAdDidClose:;渲染错误另有 didFailToRenderWithError:,视频错误另有 didFailToPlayWithError:。插屏实例为一次性使用,展示或关闭后再次加载须创建新实例。
请求失败、广告关闭或业务放弃展示时,先置空 delegate,调用 destroy 并释放持有的广告;下次创建新实例。