InterstitialVC.m
此步骤的extra字典中支持传入相关配置广告的参数与您的自定义参数,您可以在这里查看更多关于extra参数的说明。
//导入头文件
#import <AnyThinkInterstitial/AnyThinkInterstitial.h>
@interface InterstitialVC () <ATAdLoadingDelegate, ATInterstitialDelegate>
@property (nonatomic, assign) NSInteger retryAttempt; // 重试次数计数器
@end
@implementation InterstitialVC
//广告位ID
#define InterstitialPlacementID @"b680a1e0ae7a43"
//场景ID,可选,可在后台生成。没有可传入空字符串
#define InterstitialSceneID @""
#pragma mark - Load Ad 加载广告
/// 加载广告按钮被点击
- (void)loadAd {
NSMutableDictionary * loadConfigDict = [NSMutableDictionary dictionary];
//可选接入,设置加载透传参数
[loadConfigDict setValue:@"media_val_InterstitialVC" forKey:kATAdLoadingExtraMediaExtraKey];
[[ATAdManager sharedManager] loadADWithPlacementID:InterstitialPlacementID extra:loadConfigDict delegate:self];
}
/// 广告位加载完成
/// - Parameter placementID: 广告位ID
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
// 重置重试次数
self.retryAttempt = 0;
}
/// 广告位加载失败
/// - Parameters:
/// - placementID: 广告位ID
/// - error: 错误信息
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
// 重试已达到 3 次,不再重试加载
if (self.retryAttempt >= 3) {
return;
}
self.retryAttempt++;
// Calculate delay time: power of 2, maximum 8 seconds
NSInteger delaySec = pow(2, MIN(3, self.retryAttempt));
// Delayed retry loading ad
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadAd];
});
}
- 如果您需要在加载成功的回调(didFinishLoadingADWithPlacementID:)中展示广告,为了避免广告无法正常展示,请您确保当前应用位于前台再调用展示方法。
- 统计场景到达率,呈现在后台的 数据报表 -> 漏斗分析报表 -> 到达广告场景 ,在展示广告前调用。
#pragma mark - Show Ad 展示广告
/// 展示广告
- (void)showAd {
//场景统计功能,呈现在后台的 数据报表 -> 漏斗分析报表 -> 到达广告场景 ,在展示广告前调用。可选接入
[[ATAdManager sharedManager] entryInterstitialScenarioWithPlacementID:InterstitialPlacementID scene:InterstitialSceneID];
//检查是否有就绪
if (![[ATAdManager sharedManager] interstitialReadyForPlacementID:InterstitialPlacementID]) {
[self loadAd];
return;
}
//展示配置,Scene传入后台的场景ID,没有可传入空字符串,showCustomExt参数可传入自定义参数字符串
ATShowConfig *config = [[ATShowConfig alloc] initWithScene:InterstitialSceneID showCustomExt:@"testShowCustomExt"];
//展示广告
//若是全屏插屏,inViewController可传入根控制器,如tabbarController或navigationController,让广告遮挡住tabbar或navigationBar
[[ATAdManager sharedManager] showInterstitialWithPlacementID:InterstitialPlacementID
showConfig:config
inViewController:self
delegate:self
nativeMixViewBlock:nil];
}
/// 获得展示收益
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)didRevenueForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// 广告已经展示
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)interstitialDidShowForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// 广告展示失败
/// - Parameters:
/// - placementID: 广告位ID
/// - error: 错误信息
/// - extra: 额外信息字典
- (void)interstitialFailedToShowForPlacementID:(NSString *)placementID error:(NSError *)error extra:(NSDictionary *)extra {
}
/// 视频播放失败
/// - Parameters:
/// - placementID: 广告位ID
/// - error: 错误信息
/// - extra: 额外信息字典
- (void)interstitialDidFailToPlayVideoForPlacementID:(NSString *)placementID error:(NSError *)error extra:(NSDictionary *)extra {
// 预加载下一个广告
[self loadAd];
}
/// 视频开始播放
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)interstitialDidStartPlayingVideoForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// 视频结束播放
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)interstitialDidEndPlayingVideoForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// 广告已经关闭
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)interstitialDidCloseForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
// 预加载下一个广告
[self loadAd];
}
/// 广告已被点击(跳转)
/// - Parameters:
/// - placementID: 广告位ID
/// - extra: 额外信息字典
- (void)interstitialDidClickForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
类名/文件名 | 简介 |
---|---|
ATAdManager | 广告的基础操作类,包括广告加载、过滤广告、场景统计等功能。 |
ATAdManager (Interstitial) | 针对插屏广告的操作拓展,提供广告展示、检查缓存、检查广告是否就绪、场景统计等功能,其中有Extra键的定义。 |
ATAdLoadingDelegate | 广告的基础代理回调声明,包括广告位与广告源级别的加载成功或失败回调,以及竞价广告源的竞价结束与竞价失败回调。 |
ATInterstitialDelegate | 针对插屏广告类型的代理回调,包括展示、点击和关闭等。 |
ATSDKGlobalSetting | 通用设置类,提供形如清除广告内存中的缓存、自定义流量分组设置、测试模式、设置第三方广告SDK相关信息等功能,还声明了一些通用的属性。 |