💡Tips: 类名可以自定义,但需要与后台配置的自定义广告平台类名保持一致,例如后台添加的适配器类名为:DemoCustomSplashAdapter,则需对应创建DemoCustomSplashAdapter.m文件
Splash/
├── DemoCustomSplashAdapter.h # 开屏广告适配器头文件
├── DemoCustomSplashAdapter.m # 开屏广告适配器实现文件
├── DemoCustomSplashDelegate.h # 开屏广告代理头文件
└── DemoCustomSplashDelegate.m # 开屏广告代理实现文件
您需要继承 DemoCustomBaseAdapter 并重写相关方法:
loadADWithArgument: 方法adReadySplashWithInfo: 方法showSplashInViewController: 方法| 方法 | 参数说明 | 作用 |
|---|---|---|
| - (void)loadADWithArgument:(ATAdMediationArgument *)argument | argument: 包含有服务器下发和本地配置的参数 | 用于获取服务器下发和本地配置的参数,实现自定义广告的加载逻辑 |
| - (void)showSplashInViewController:(UIViewController *)viewController | viewController: 展示广告时传入的 UIViewController | 实现展示自定义广告的逻辑 |
| - (BOOL)adReadySplashWithInfo:(NSDictionary *)info | info: 广告信息字典 | 用于展示广告前判断自定义广告是否准备就绪 |
开屏广告适配器支持以下回调方法,这些方法继承自 ATBaseTrackProtocol 协议:
| 方法 | 说明 |
|---|---|
| - (void)atOnAdMetaLoadFinish:(NSDictionary *)adExtra | 广告数据加载完成时执行回调给开发者 |
| - (void)atOnAdLoadFailed:(NSError *)error adExtra:(NSDictionary *)adExtra | 广告加载失败时执行回调给开发者 |
| - (void)atOnAdShow:(NSDictionary *)adExtra | 广告展示成功时执行回调给开发者 |
| - (void)atOnAdShowFailed:(NSError *)error extra:(NSDictionary *)extraDic | 广告展示失败时执行回调给开发者 |
| - (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)atOnAdDidRevenue:(NSDictionary *)extraDic | 广告收益回调给开发者 |
- 导入了头文件
#import <AnyThinkSDK.h>- 添加属性:
@property (nonatomic, strong) ATAdStatusBridge * adStatusBridge;- 遵循您的第三方广告 SDK 开屏广告的回调协议
示例如下:
objc 复制代码//导入头文件 #import <AnyThinkSDK/AnyThinkSDK.h> #import <Foundation/Foundation.h> @interface DemoCustomSplashDelegate : NSObject<YourSplashAdDelegate> @property (nonatomic, strong) ATAdStatusBridge * adStatusBridge; @end
- 实现您的第三方 SDK 的协议方法,例如广告加载成功,广告点击,广告关闭等。
- 在第三方SDK的广告加载成功事件中,调用通知我们广告加载成功
objc 复制代码// 广告加载成功 - (void)splashAdDidLoad:(YourSplashAd *)splashAd { [self.adStatusBridge atOnAdMetaLoadFinish:{}]; }
- 在第三方SDK的广告加载失败事件中,调用通知我们广告加载失败
objc 复制代码// 广告加载失败 - (void)splashAdDidFailToLoad:(YourSplashAd *)splashAd error:(NSError *)error { [self.adStatusBridge atOnAdLoadFailed:error adExtra:nil]; }
- 参考我们SDK协议,实现其他广告事件并通知我们:
objc 复制代码// 广告加载成功 - (void)splashAdDidLoad:(YourSplashAd *)splashAd { [self.adStatusBridge atOnAdMetaLoadFinish:{}]; } // 广告展示成功 - (void)splashAdDidShow:(YourSplashAd *)splashAd { [self.adStatusBridge atOnAdShow:nil]; } // 广告点击 - (void)splashAdDidClick:(YourSplashAd *)splashAd { [self.adStatusBridge atOnAdClick:nil]; } // 广告关闭 - (void)splashAdDidClose:(YourSplashAd *)splashAd { [self.adStatusBridge atOnAdClosed:nil]; }
- 继承 DemoCustomBaseAdapter
- 导入了头文件
#import <AnyThinkSDK.h>- 遵循
ATBaseSplashAdapterProtocol协议
- 添加以下属性:
objc 复制代码@interface DemoCustomSplashAdapter() @property (nonatomic, strong) DemoCustomSplashDelegate *splashDelegate; @property (nonatomic, strong) YourSplashAd *splashAd; @end
- 初始化
splashDelegate属性objc 复制代码#pragma mark - lazy - (DemoCustomSplashDelegate *)splashDelegate{ if (_splashDelegate == nil) { _splashDelegate = [[DemoCustomSplashDelegate alloc] init]; _splashDelegate.adStatusBridge = self.adStatusBridge; } return _splashDelegate; }
- 实现广告加载方法:
objc 复制代码#pragma mark - Ad load - (void)loadADWithArgument:(ATAdMediationArgument *)argument { self.splashAd = [[YourSplashAd alloc] init]; self.splashAd.delegate = self.splashDelegate; [self.splashAd loadAdWithSlotId:argument.serverContentDic[@"slot_id"]]; }
- 实现广告展示方法:
objc 复制代码#pragma mark - Ad show - (void)showSplashInViewController:(UIViewController *)viewController { [self.splashAd showInViewController:viewController]; }
- 实现广告准备状态检查方法:
objc 复制代码#pragma mark - Ad ready - (BOOL)adReadySplashWithInfo:(NSDictionary *)info { return self.splashAd.isAdValid; }