💡Tips: 类名可以自定义,但需要与后台配置的自定义广告平台类名保持一致,例如后台添加的适配器类名为:DemoCustomInterstitialAdapter,则需对应创建DemoCustomInterstitialAdapter.m文件
Interstitial/
├── DemoCustomInterstitialAdapter.h # 插屏适配器头文件
├── DemoCustomInterstitialAdapter.m # 插屏适配器实现文件
├── DemoCustomInterstitialDelegate.h # 插屏代理头文件
└── DemoCustomInterstitialDelegate.m # 插屏代理实现文件
您需要继承 DemoCustomBaseAdapter 并重写相关方法:
- 开发者调用广告加载 API 时,会调用到自定义 Adapter 的
loadADWithArgument:方法- 开发者调用广告准备状态检查 API 时,会调用到自定义 Adapter 的
adReadyInterstitialWithInfo:方法- 开发者调用广告展示 API 时,会调用到自定义 Adapter 的
showInterstitialInViewController:方法
| 方法 | 参数说明 | 作用 |
|---|---|---|
| - (void)loadADWithArgument:(ATAdMediationArgument *)argument | argument: 包含有服务器下发和本地配置的参数 | 用于获取服务器下发和本地配置的参数,实现自定义广告的加载逻辑 |
| - (void)showInterstitialInViewController:(UIViewController *)viewController | viewController: 展示广告时传入的 UIViewController | 实现展示自定义广告的逻辑 |
| - (BOOL)adReadyInterstitialWithInfo:(NSDictionary *)info | info: 广告信息字典 | 用于展示广告前判断自定义广告是否准备就绪 |
插屏广告适配器支持以下回调方法,这些方法继承自 ATBaseTrackProtocol 和 ATInterstitialTrackProtocol 协议:
| 方法 | 说明 |
|---|---|
| - (void)atOnAdMetaLoadFinish:(NSDictionary *)adExtra | 广告数据加载完成时执行回调给您 |
| - (void)atOnAdLoadFailed:(NSError *)error adExtra:(NSDictionary *)adExtra | 广告加载失败时执行回调给您 error: 错误信息 |
| - (void)atOnAdShow:(NSDictionary *)adExtra | 广告展示成功时执行回调给您 |
| - (void)atOnAdShowFailed:(NSError *)error extra:(NSDictionary *)extraDic | 广告展示失败时执行回调给您 error: 错误信息 |
| - (void)atOnAdClick:(NSDictionary *)adExtra | 广告被用户点击时执行回调给您 |
| - (void)atOnAdWillClosed:(NSDictionary *)extra | 广告即将关闭时执行回调给您 |
| - (void)atOnAdClosed:(NSDictionary *)extra | 广告已关闭时执行回调给您 |
| - (void)atOnAdDetailWillShow:(NSDictionary *)extra | 广告详情页即将展现时执行回调给您 |
| - (void)atOnAdDetailClosed:(NSDictionary *)extra | 广告详情页已关闭时执行回调给您 |
| - (void)atOnAdDeeplinkOrJumpResult:(BOOL)success | 广告 Deeplink 跳转结果回调给您 |
| - (void)atOnAdVideoStart:(NSDictionary *)extra | 广告视频开始播放时执行回调给您 |
| - (void)atOnAdVideoEnd:(NSDictionary *)extra | 广告视频播放结束时执行回调给您 |
| - (void)atOnAdDidFailToPlayVideo:(NSError *)error extra:(NSDictionary *)extraDic | 广告视频播放失败时执行回调给您 error: 错误信息 |
| - (void)atOnAdDidRevenue:(NSDictionary *)extraDic | 广告收益回调给您 |
| 方法 | 说明 |
|---|---|
| - (void)atOnInterstitialAdLoadedExtra:(NSDictionary *)adExtra | 插屏广告加载成功时执行回调给您 |
- 导入头文件
#import <AnyThinkSDK.h>- 添加属性:
@property (nonatomic, strong) ATInterstitialAdStatusBridge * adStatusBridge;- 遵循您接入的广告平台的插屏广告回调协议,例如本例中是
MSInterstitialDelegate
示例如下:objc 复制代码#import <AnyThinkSDK/AnyThinkSDK.h> #import <Foundation/Foundation.h> #import "DemoCustomAdapterCommonHeader.h" @interface DemoCustomInterstitialDelegate : NSObject<MSInterstitialDelegate> @property (nonatomic, strong) ATInterstitialAdStatusBridge * adStatusBridge; @end
- 实现您的第三方 SDK 的协议方法,例如广告加载成功,广告点击,广告关闭等。
- 在第三方SDK的广告加载成功事件中,调用通知我们广告加载成功,例如:
objc 复制代码/** 平台广告展示准备就绪,可以进行展示 在此回调中调用show接口展示广告 */ - (void)msInterstitialAdReadySuccess:(MSInterstitialAd *)msInterstitialAd { //这是第三方 SDK 的协议方法,广告加载成功时调用 [self.adStatusBridge atOnInterstitialAdLoadedExtra:@{}]; }
- 在第三方SDK的广告加载失败事件中,调用通知我们广告加载失败,例如:
objc 复制代码/** * 广告预加载失败回调 * 详解:当接收服务器返回的广告数据失败后调用该函数 */ - (void)msInterstitialError:(MSInterstitialAd *)msInterstitialAd error:(NSError *)error {//这是第三方 SDK 的协议方法,广告加载失败时调用 //通知我们加载失败 [self.adStatusBridge atOnAdLoadFailed:error adExtra:nil]; }
- 实现其他广告事件并通知我们,例如:
objc 复制代码/** * 插屏广告点击回调 */ - (void)msInterstitialClicked:(MSInterstitialAd *)msInterstitialAd { [self.adStatusBridge atOnAdClick:nil]; } /** * 插屏广告视图展示成功回调 * 详解: 插屏广告展示成功回调该函数 */ - (void)msInterstitialShow:(MSInterstitialAd *)msInterstitialAd { [self.adStatusBridge atOnAdShow:nil]; } /** * 插屏广告展示结束回调 * 详解: 插屏广告展示结束回调该函数 */ - (void)msInterstitialClosed:(MSInterstitialAd *)msInterstitialAd { [self.adStatusBridge atOnAdClosed:nil]; } /** 平台广告展示失败 详解:可能广告素材异常或三方异常导致无法广告曝光 */ - (void)msInterstitialAdShowFail:(MSInterstitialAd *)msInterstitialAd error:(NSError *)error { [self.adStatusBridge atOnAdShowFailed:error extra:nil]; } /** * 全屏广告页被关闭 */ - (void)msInterstitialDetailClosed:(MSInterstitialAd *)msInterstitialAd { [self.adStatusBridge atOnAdDetailClosed:nil]; }
- 继承 DemoCustomBaseAdapter
- 导入头文件
#import <AnyThinkSDK.h>- 遵循
ATBaseInterstitialAdapterProtocol协议
- 添加以下属性:
objc 复制代码@interface DemoCustomInterstitialAdapter() // 本文档4.1中实现的 @property (nonatomic, strong) DemoCustomInterstitialDelegate * interstitialDelegate; // 第三方SDK 的插屏广告对象 @property (nonatomic, strong) MSInterstitialAd *interstitialAd; @end
- 初始化
interstitialDelegate属性objc 复制代码#pragma mark - lazy - (DemoCustomInterstitialDelegate *)interstitialDelegate{ if (_interstitialDelegate == nil) { _interstitialDelegate = [[DemoCustomInterstitialDelegate alloc] init]; _interstitialDelegate.adStatusBridge = self.adStatusBridge; } return _interstitialDelegate; }
- 实现广告加载方法:
objc 复制代码#pragma mark - Ad load - (void)loadADWithArgument:(ATAdMediationArgument *)argument { //通过argument对象获取必要的加载信息,创建好必要的参数,准备传入给第三方的插屏加载方法,开始加载广告 self.interstitialAd = [[MSInterstitialAd alloc] init]; //注意设置代理给DemoCustomInterstitialDelegate self.interstitialAd.delegate = self.interstitialDelegate; MSInterstitialAdConfigParams *adParam = [[MSInterstitialAdConfigParams alloc]init]; adParam.videoMuted = [argument.localInfoDic[@"video_muted"] intValue] == 0 ? NO : YES; adParam.isNeedCloseAdAfterClick = [argument.localInfoDic[@"click_close"] intValue] == 0 ? NO : YES; [self.interstitialAd loadAdWithPid:argument.serverContentDic[@"slot_id"] adConfigParams:adParam]; }
- 实现广告展示方法:
objc 复制代码#pragma mark - Ad show - (void)showInterstitialInViewController:(UIViewController *)viewController { [self.interstitialAd showAdFromRootViewController:viewController]; }
- 实现广告准备状态检查方法:
objc 复制代码#pragma mark - Ad ready - (BOOL)adReadyInterstitialWithInfo:(NSDictionary *)info { return self.interstitialAd.isAdValid; }