客户为了让APP启动的时候,有一点点广告收益,于是就接入了穿山甲的广告SDK,这次接入的是的开屏广告。于是记录一下接入穿山甲广告的过程和遇到的一些问题。
一、xcode相关的配置信息
1.1.info-plist文件中
添加Privacy - Tracking Usage Description
获取IDFA有助于提供更优质的个性化服务及内容
<key>NSUserTrackingUsageDescription</key>
<string>获取IDFA有助于提供更优质的个性化服务及内容</string>
1.2.路径 Targets--Build Phases--Link Binary With Libraries
添加相关的framework,具体可以参考官网

1.3.podFile文件配置
pod 'Ads-CN', "~> 6.7.1.3"
# 这里为穿山甲自测工具,可选择添加
pod 'BUAdTestMeasurement', "~> 6.7.1.3"
二、普通的开屏广告(BUSplashAd展示 + 自定义viewController展示)
1.在APPDelegate 中直接通过BUSplashAd展示,注意这里的⭐️1,2,3,为重要的配置
// 启动页
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setupBUAdSDK];
[self initEntranchWindow];
}
// 初始化界面
- (void)initEntranchWindow {
if (self.window == nil) {
UIWindow *keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[keyWindow makeKeyAndVisible];
self.window = keyWindow;
self.window.rootViewController = [self rootViewController];
self.window.hidden = YES;
}
}
- (UIViewController *)rootViewController {
BUDMainViewController *mainViewController = [[BUDMainViewController alloc] init];
UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:mainViewController];
return navigationVC;
}
// 穿山甲广告初始化配置
- (void)setupBUAdSDK {
#if __has_include(<BUAdTestMeasurement/BUAdTestMeasurement.h>)
#if DEBUG
// 测试工具
[BUAdTestMeasurementConfiguration configuration].debugMode = YES;
#endif
#endif
BUAdSDKConfiguration *configuration = [BUAdSDKConfiguration configuration];
// 1.⭐️@"穿山甲广告官网生成的应用ID"
configuration.appID = [BUDAdManager appKey];
configuration.privacyProvider = [[BUDPrivacyProvider alloc] init];
configuration.appLogoImage = [UIImage imageNamed:@"AppIcon"];
configuration.debugLog = @(1);
// 如果使用聚合维度功能,则务必将以下字段设置为YES
// 并检查工程有引用CSJMediation.framework,这样SDK初始化时将启动聚合相关必要组件
configuration.useMediation = NO;
// 聚合广告的设置,开屏广告可配置,也可不配置
[self useMediationSettings];
[BUAdSDKManager startWithAsyncCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
// 聚合维度首次预缓存,开屏广告可有可无
// [self useMediationPreload];
// 2.⭐️⭐️这里是开屏广告的配置
[self addSplashAD];
// 这里是广告的一些测试工具,可有可无
[self configDemo];
// Setup live stream ad
});
}
}];
// [self playerCoustomAudio];
// ⭐️3.这个的配置需要开启IDFA
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self requestIDFATracking];
});
}
// 获取本机IDFA配置
- (void)requestIDFATracking {
if (@available(iOS 14, *)) {
// iOS14及以上版本需要先请求权限
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// 获取到权限后,依然使用老方法获取idfa
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"%@",idfa);
} else {
NSLog(@"请在设置-隐私-跟踪中允许App请求跟踪");
}
}];
} else {
// iOS14以下版本依然使用老方法
// 判断在设置-隐私里用户是否打开了广告跟踪
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"%@",idfa);
} else {
NSLog(@"请在设置-隐私-广告中打开广告跟踪功能");
}
}
}
#pragma mark - 开屏广告相关的配置
- (void)addSplashAD {
CGRect frame = [UIScreen mainScreen].bounds;
self.startTime = CACurrentMediaTime();
// ⭐️穿山甲开屏广告代码位id,官网上通过APPKey申请的广告位id,一般新建的广告位半个小时至1小时后可测
BUSplashAd *splashAd = [[BUSplashAd alloc] initWithSlotID:express_splash_ID adSize:frame.size];
splashAd.supportCardView = YES;
splashAd.supportZoomOutView = YES;
// 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
splashAd.delegate = self;
// ⭐️cardDelegate,zoomOutDelegate在配置了点睛的时候需要
splashAd.cardDelegate = self;
splashAd.zoomOutDelegate = self;
// ⭐️设置开屏的广告显示时间
splashAd.tolerateTimeout = 3;
/***
广告加载成功的时候,会立即渲染WKWebView。
如果想预加载的话,建议一次最多预加载三个广告,如果超过3个会很大概率导致WKWebview渲染失败。
*/
self.splashAd = splashAd;
[self.splashAd loadAdData];
}
#pragma mark -- BUMSplashAdDelegate代理方法
// 开屏成功调用
- (void)splashAdLoadSuccess:(nonnull BUSplashAd *)splashAd {
UIWindow *keyWindow = self.window;
[splashAd showSplashViewInRootViewController:keyWindow.rootViewController];
}
// 开屏失败
- (void)splashAdLoadFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
// ⭐️这里的失败可以自己打印出来
NSDictionary * userInfo = error.userInfo;
NSString * msgString = [NSString stringWithFormat:@"%@",userInfo[@"desc"]];
NSString * msgCode = [NSString stringWithFormat:@"%ld",(long)error.code];
NSString * msgReson = [NSString stringWithFormat:@"%@",userInfo[@"reason"]];
NSString * msgResult = [NSString stringWithFormat:@"%@-%@,%@",msgCode,msgReson,msgString];
NSLog(@"splashAdLoadFail当前的报错信息为:%@",msgResult);
[self pbu_logWithSEL:_cmd msg:@""];
}
// 失败
- (void)splashAdRenderFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
// ⭐️这里的失败可以自己打印出来
NSDictionary * userInfo = error.userInfo;
NSString * msgString = [NSString stringWithFormat:@"%@",userInfo[@"desc"]];
NSString * msgCode = [NSString stringWithFormat:@"%ld",(long)error.code];
NSString * msgReson = [NSString stringWithFormat:@"%@",userInfo[@"reason"]];
NSString * msgResult = [NSString stringWithFormat:@"%@-%@,%@",msgCode,msgReson,msgString];
NSLog(@"splashAdRenderFail当前的报错信息为:%@",msgResult);
[self pbu_logWithSEL:_cmd msg:@""];
}
// 成功
- (void)splashAdRenderSuccess:(nonnull BUSplashAd *)splashAd {
[self pbu_logWithSEL:_cmd msg:@""];
}
// 广告将要展示
- (void)splashAdWillShow:(nonnull BUSplashAd *)splashAd {
[self pbu_logWithSEL:_cmd msg:@""];
}
// 广告开始展示
- (void)splashAdDidShow:(nonnull BUSplashAd *)splashAd {
[self pbu_logWithSEL:_cmd msg:@""];
}
// 广告位点击
- (void)splashAdDidClick:(nonnull BUSplashAd *)splashAd {
[self pbu_logWithSEL:_cmd msg:@""];
}
// 广告位关闭
- (void)splashAdDidClose:(nonnull BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
[self pbu_logWithSEL:_cmd msg:@""];
}
2.使用viewController切换控制器展示
首先要建立一个自定义的广告类BUDSplashContainerViewController,这里直接用了官方demo中的实体类进行了修改。
2.1 AppDelegate.m文件
//引用
// BUDSplashContainerViewController可以仿照官网demo里BUDSplashContainerViewController重新写,这里直接拿了改造
#import "BUDSplashContainerViewController.h"
property (nonatomic, strong) BUSplashAd *splashAd;
@property (nonatomic, strong) BUDSplashContainerViewController *customSplashVC;
// 启动页空白的问题
@property (nonatomic, strong) UIWindow * adWindow;
//启动页
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 系统的启动页-- 延迟1s
[NSThread sleepForTimeInterval:1];
// 配置广告页
// initialize AD SDK,同上面的配置
[self setupBUAdSDK];
// 同上面的配置
[self initEntranchWindow];
// 添加广告页
[self createSlashVC];
return YES;
}
// 广告vc配置
- (void)createSlashVC {
self.adWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_customSplashVC = [[BUDSplashContainerViewController alloc] init];
self.adWindow.backgroundColor = [UIColor whiteColor];
self.adWindow.rootViewController = self.customSplashVC;
self.adWindow.windowLevel = UIWindowLevelAlert; // 或者UIWindowLevelStatusBar + 1
self.adWindow.hidden = NO;
[_customSplashVC loadSplashAd];
self.customSplashVC.delegate = self;
}
2.2 BUDSplashContainerViewController.h文件
#import <UIKit/UIKit.h>
#import <BUAdSDK/BUAdSDK.h>
NS_ASSUME_NONNULL_BEGIN
@protocol BUDSplashContainerViewControllerDelegate <NSObject>
// 成功的回调
- (void)containSplashAdLoadSuccess:(BUSplashAd *)splashAd;
- (void)containSplashAdRenderSuccess:(BUSplashAd *)splashAd;
// 失败回调
- (void)containSplashAdFailure:(BUSplashAd *)splashAd error:(BUAdError * _Nullable)error ;
// 定时器结束的回调
- (void)containSplashTimerSuccessWithTime:(NSInteger)lastTime andWith:(BUSplashAd *)splashAd;
@end
@interface BUDSplashContainerViewController : UIViewController
@property (nonatomic, weak)id<BUDSplashContainerViewControllerDelegate>delegate;
- (void)loadSplashAd;
@end
2.3 BUDSplashContainerViewController.m文件
#import "BUDSplashContainerViewController.h"
#import "BUDSplashViewController.h"
#import <BUAdSDK/BUAdSDK.h>
#import "BUDNormalButton.h"
#import "BUDMacros.h"
#import "NSString+LocalizedString.h"
#import "UIView+Draw.h"
#import "BUDAnimationTool.h"
#import "BUDSlotID.h"
@interface BUDSplashContainerViewController () <BUSplashAdDelegate, BUSplashCardDelegate, BUSplashZoomOutDelegate>
@property (nonatomic, strong) BUSplashAd *splashAd;
//⭐️自定义的倒计时button
@property (nonatomic, strong) UIButton * countDownButton;
@property (strong,nonatomic) NSTimer * countDownTimer;
@property (nonatomic, assign) NSInteger remainingTime;
@end
@implementation BUDSplashContainerViewController
- (void)startCountdown {
__weak typeof(self) weakSelf = self;
self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(updateCountDownTimer:) userInfo:nil repeats:YES];
}
- (void)updateCountDownTimer:(NSTimer *)timer {
__weak typeof(self) weakSelf = self;
NSLog(@"这里的定时器还在跑呀!!!");
weakSelf.remainingTime--; // 减少剩余时间
NSString * countDownTitle = [NSString stringWithFormat:@"跳过 %ld", (long)weakSelf.remainingTime];
[weakSelf.countDownButton setTitle:countDownTitle forState:UIControlStateNormal];
if (weakSelf.remainingTime <= 0) {
[weakSelf.countDownTimer invalidate]; // 停止定时器
[weakSelf.countDownButton setTitle:@"跳过 3" forState:UIControlStateNormal];
// [self dismiss];
//containSplashTimerSuccess
if ([weakSelf.delegate respondsToSelector:@selector(containSplashTimerSuccessWithTime:andWith:)]) {
[weakSelf.delegate containSplashTimerSuccessWithTime:weakSelf.remainingTime andWith:weakSelf.splashAd];
}
weakSelf.countDownTimer = nil;
// 移除View呀
[weakSelf.splashAd removeSplashView];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.remainingTime = 3;
}
- (void)loadSplashAd {
BUSplashAd *splashAd = [[BUSplashAd alloc] initWithSlotID:express_splash_ID adSize:self.view.bounds.size];
splashAd.supportCardView = YES;
splashAd.supportZoomOutView = YES;
// 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
splashAd.delegate = self;
splashAd.cardDelegate = self;
splashAd.zoomOutDelegate = self;
splashAd.tolerateTimeout = 3;
splashAd.hideSkipButton = YES;
[splashAd loadAdData];
self.splashAd = splashAd;
}
- (void)dismiss {
[self removeFromParentViewController];
[self.view removeFromSuperview];
}
#pragma mark - BUSplashOldDelegate
- (void)splashAdLoadSuccess:(BUSplashAd *)splashAd {
[splashAd showSplashViewInRootViewController:self];
if ([self.delegate respondsToSelector:@selector(containSplashAdLoadSuccess:)]) {
[self.delegate containSplashAdLoadSuccess:splashAd];
}
}
- (void)splashAdLoadFail:(BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
NSLog(@"这里是请求失败了呀");
NSDictionary * userInfo = error.userInfo;
NSString * msgString = [NSString stringWithFormat:@"%@",userInfo[@"desc"]];
NSString * msgCode = [NSString stringWithFormat:@"%ld",(long)error.code];
NSString * msgReson = [NSString stringWithFormat:@"%@",userInfo[@"reason"]];
NSString * msgResult = [NSString stringWithFormat:@"%@-%@,%@",msgCode,msgReson,msgString];
NSLog(@"ADLoad当前的报错信息为:%@",msgResult);
if ([self.delegate respondsToSelector:@selector(containSplashAdFailure:error:)]) {
[self.delegate containSplashAdFailure:splashAd error:error];
}
}
- (void)countDownButtonAction {
NSLog(@"点击自定义跳过的按钮呀!!!");
// [self dismiss];
self.remainingTime = 0;
//containSplashTimerSuccess
if ([self.delegate respondsToSelector:@selector(containSplashTimerSuccessWithTime:andWith:)]) {
[self.delegate containSplashTimerSuccessWithTime:self.remainingTime andWith:self.splashAd];
}
[self.splashAd removeSplashView];
}
- (void)splashAdRenderSuccess:(BUSplashAd *)splashAd {
// 渲染成功再展示视图控制器
// UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
// [keyWindow.rootViewController addChildViewController:self];
// [keyWindow.rootViewController.view addSubview:self.view];
//
// ⭐️⭐️这个位置加载自定义的跳过按钮
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat safeTopMargin = 32;
if (@available(iOS 11.0, *)) {
safeTopMargin = self.view.safeAreaInsets.top;
}
if (splashAd.hideSkipButton == YES) {
NSLog(@"隐藏自定义的跳过按钮呀!!");
self.countDownButton = [[UIButton alloc]initWithFrame:CGRectMake(width-56-12, 44, 56, 20)];
NSString * buttonTitle = [NSString stringWithFormat:@"跳过 %ld",self.remainingTime];
[ self.countDownButton setTitle:buttonTitle forState:UIControlStateNormal];
[ self.countDownButton addTarget:self action:@selector(countDownButtonAction) forControlEvents:UIControlEventTouchUpInside];
// 设置字体颜色,背景色圆角
[ self.countDownButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.countDownButton.titleLabel.font = [UIFont systemFontOfSize:15];
self.countDownButton.backgroundColor = [UIColor blackColor];
self.countDownButton.layer.cornerRadius = 10;
self.countDownButton.layer.masksToBounds = YES;
[splashAd.splashView addSubview:self.countDownButton];
// 开启倒计时:
[self startCountdown];
}
if ([self.delegate respondsToSelector:@selector(containSplashAdRenderSuccess:)]){
[self.delegate containSplashAdRenderSuccess:splashAd];
}
}
- (void)splashAdRenderFail:(BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
NSLog(@"这里是请求失败了呀");
NSDictionary * userInfo = error.userInfo;
NSString * msgString = [NSString stringWithFormat:@"%@",userInfo[@"desc"]];
NSString * msgCode = [NSString stringWithFormat:@"%ld",(long)error.code];
NSString * msgReson = [NSString stringWithFormat:@"%@",userInfo[@"reason"]];
NSString * msgResult = [NSString stringWithFormat:@"%@-%@,%@",msgCode,msgReson,msgString];
NSLog(@"splashAdRenderFail当前的报错信息为:%@",msgResult);
if ([self.delegate respondsToSelector:@selector(containSplashAdFailure:error:)]) {
[self.delegate containSplashAdFailure:splashAd error:error];
}
}
- (void)splashAdWillShow:(BUSplashAd *)splashAd {
}
- (void)splashAdDidShow:(BUSplashAd *)splashAd {
}
- (void)splashAdDidClick:(BUSplashAd *)splashAd {
}
- (void)splashAdDidClose:(BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
}
- (void)splashAdViewControllerDidClose:(BUSplashAd *)splashAd {
[self dismiss];
}
- (void)splashDidCloseOtherController:(nonnull BUSplashAd *)splashAd interactionType:(BUInteractionType)interactionType {
NSString *str;
if (interactionType == BUInteractionTypePage) {
str = @"ladingpage";
} else if (interactionType == BUInteractionTypeVideoAdDetail) {
str = @"videoDetail";
} else {
str = @"appstoreInApp";
}
[self pbud_logWithSEL:_cmd msg:str];
}
- (void)splashVideoAdDidPlayFinish:(BUSplashAd *)splashAd didFailWithError:(nullable NSError *)error {
}
#pragma mark - BUSplashCardDelegate
- (void)splashCardReadyToShow:(BUSplashAd *)splashAd {
[splashAd showCardViewInRootViewController:[[[UIApplication sharedApplication] delegate] window].rootViewController];
}
- (void)splashCardViewDidClick:(BUSplashAd *)splashAd {
}
- (void)splashCardViewDidClose:(BUSplashAd *)splashAd {
}
#pragma mark - BUSplashZoomOutDelegate
- (void)splashZoomOutReadyToShow:(BUSplashAd *)splashAd {
[splashAd showCardViewInRootViewController:[[[UIApplication sharedApplication] delegate] window].rootViewController];
}
- (void)splashZoomOutViewDidClick:(BUSplashAd *)splashAd {
}
- (void)splashZoomOutViewDidClose:(BUSplashAd *)splashAd {
}
- (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
BUD_Log(@"SDKDemoDelegate BUSplashAdView In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
}
三、自定义点睛的开屏广告
(具体代码见上面的:BUDSplashContainerViewController.h .m文件)
3.1设置点睛的时候,需要在 loadSplashAd方法中配置splashAd.hideSkipButton = YES;
loadSplashAd配置如下:
- (void)loadSplashAd {
BUSplashAd *splashAd = [[BUSplashAd alloc] initWithSlotID:express_splash_ID adSize:self.view.bounds.size];
splashAd.supportCardView = YES;
splashAd.supportZoomOutView = YES;
// 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
splashAd.delegate = self;
splashAd.cardDelegate = self;
splashAd.zoomOutDelegate = self;
splashAd.tolerateTimeout = 3;
// 是否设置点睛的效果
splashAd.hideSkipButton = YES;
[splashAd loadAdData];
self.splashAd = splashAd;
}
3.2需要在代理方法中添加自定义的跳过按钮
- (void)splashAdRenderSuccess:(BUSplashAd *)splashAd {
// ⭐️⭐️这个位置加载自定义的跳过按钮
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat safeTopMargin = 32;
if (@available(iOS 11.0, *)) {
safeTopMargin = self.view.safeAreaInsets.top;
}
if (splashAd.hideSkipButton == YES) {
NSLog(@"隐藏自定义的跳过按钮呀!!");
self.countDownButton = [[UIButton alloc]initWithFrame:CGRectMake(width-56-12, 44, 56, 20)];
NSString * buttonTitle = [NSString stringWithFormat:@"跳过 %ld",self.remainingTime];
[ self.countDownButton setTitle:buttonTitle forState:UIControlStateNormal];
[ self.countDownButton addTarget:self action:@selector(countDownButtonAction) forControlEvents:UIControlEventTouchUpInside];
// 设置字体颜色,背景色圆角
[ self.countDownButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.countDownButton.titleLabel.font = [UIFont systemFontOfSize:15];
self.countDownButton.backgroundColor = [UIColor blackColor];
self.countDownButton.layer.cornerRadius = 10;
self.countDownButton.layer.masksToBounds = YES;
[splashAd.splashView addSubview:self.countDownButton];
// 开启倒计时:
[self startCountdown];
}
}
3.3开屏广告出现白屏的问题及解决方法
在进入界面的时候,用闪屏页来打底,设置闪屏页显示的时间,抵消掉白屏
将广告层vc添加到新的adWindow上,并将adWindow置顶。
在createSlashVC中修改:
@interface AppDelegate ()
// 新建一个新的window层
@property (nonatomic, strong) UIWindow * adWindow;
@end
// 修改方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 系统的启动页-- 延迟1s
[NSThread sleepForTimeInterval:1];
}
- (void)createSlashVC {
self.adWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.customSplashVC = [[BUDSplashContainerViewController alloc] init];
self.adWindow.backgroundColor = [UIColor clearColor];
/// lunchImageView配置
UIImageView *launchImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lunchImage"]];
launchImageView.frame = self.customSplashVC.view.bounds;
[_customSplashVC.view insertSubview:launchImageView atIndex:0];
self.adWindow.rootViewController = self.customSplashVC;
self.adWindow.windowLevel = UIWindowLevelAlert; // 或者UIWindowLevelStatusBar + 1
self.adWindow.hidden = NO;
[_customSplashVC loadSplashAd];
self.customSplashVC.delegate = self;
}
#pragma mark -- BUDSplashContainerViewControllerDelegate
/// 处理失败
-(void)containSplashAdFailure:(BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
- (void)containSplashAdDidShow:(BUSplashAd *)splashAd {
self.adWindow.hidden = NO;
NSLog(@"配置的广告开始展示了");
}
// 开屏广告结束后,进入APP首页吧
- (void)containSplashAdLoadSuccess:(BUSplashAd *)splashAd {
NSLog(@"成功结束1");
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
- (void)containSplashAdRenderSuccess:(BUSplashAd *)splashAd {
NSLog(@"成功结束22222");
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
// 定时器结束的回调
- (void)containSplashTimerSuccessWithTime:(NSInteger)lastTime andWith:(BUSplashAd *)splashAd{
if (lastTime <= 0) {
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[self.customSplashVC.view removeFromSuperview];
// [splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
}
四、遇到的一些报错日志记录
4.1 线上环境需要创建一个线上的APPKey,然后再创建一个线上的广告位,在测试的时候,需要及时的和官方的客服进行联系,那边会给你开启应用id的白名单,开启代码位的白名单,方便开发测试。
4.2 报错日志记录:20001-112;20001-202;20001-228......
这种20001开头的报错日志,基本上都是你的应用id没有开启白名单功能,可以在官网联系人工客服,让他们给你的应用id开启白名单功能,然后你就可以在官网的demo首页,Tools--Test Measurement---穿山甲广告预览管理自己的广告id了。
⭐️⭐️测试的时候,要打开“全局广告预览模式”的开关。
官方demo中选中 Tool -- Test Measurement 打开按钮
如图所示:

4.3 20001-101问题:需要官方客服帮忙把广告位代码id开启白名单功能,避免测试多次后,广告报错的问题。
基本上需要自己主动联系穿山甲的官方人工客服,说明你遇到的问题。
一定要切记,联系人工客服,人工客服,人工客服!
一定要切记,联系人工客服,人工客服,人工客服!
一定要切记,联系人工客服,人工客服,人工客服!
五、关于上线AppStore遇到的问题
问题描述:你的App 包含NSUserTrackingUsageDescription,这表示它可能会请求追踪用户。要提交以供审核,请更新你的App隐私答复以注明从此App中收集的数据将用于追踪目的,或者
综合 更新你的 App二进制文件并上传新的构建版本。了解更多
首先保证代码里,infoPlist中设置了NSUserTrackingUsageDescription;然后在APP上架的界面,找到APP隐私模块,设置对应的广告数据隐私追踪即可。
⭐️⭐️ APP上线后观察:
1.广告打开后,有概率性还会出现先进入APP首页,然后再进入穿山甲的广告界面。这里的处理,不知道是不是SDK请求广告资源有延迟的原因,后续还得继续看看其他的处理方法。
2.部分机型每次打开APP进入首页,看不到穿山甲广告,打印日志如下:
请求失败报错日志:20001-101:没有匹配到合适的广告导致请求没有广告填充,一般在刚起量时较为常见,随着起量以及模型正确预估可缓解此问题;同时可降低广告请求的频率来缓解此问题。
根据穿山甲工单解释,应该是我们后台配置的广告位,都是一些主流的广告,请求次数过多,就会有限流的问题。所以展示不出来,也没有合理的解决方案。
报错日志如下:

3.部分机型每日接收广告显示,大概是3--5次每天。就会接受不到穿山甲的广告了。这个是正常的现象,同一机型,每天的广告展示是有限制的。
六、相关的参考文档
穿山甲官网帮助文档
穿山甲官网iOS集成文档