客戶為了讓APP啟動(dòng)的時(shí)候,有一點(diǎn)點(diǎn)廣告收益,于是就接入了穿山甲的廣告SDK,這次接入的是的開屏廣告。于是記錄一下接入穿山甲廣告的過程和遇到的一些問題。
一、xcode相關(guān)的配置信息
1.1.info-plist文件中
添加Privacy - Tracking Usage Description
獲取IDFA有助于提供更優(yōu)質(zhì)的個(gè)性化服務(wù)及內(nèi)容
<key>NSUserTrackingUsageDescription</key>
<string>獲取IDFA有助于提供更優(yōu)質(zhì)的個(gè)性化服務(wù)及內(nèi)容</string>
1.2.路徑 Targets--Build Phases--Link Binary With Libraries
添加相關(guān)的framework,具體可以參考官網(wǎng)

1.3.podFile文件配置
pod 'Ads-CN', "~> 6.7.1.3"
# 這里為穿山甲自測工具,可選擇添加
pod 'BUAdTestMeasurement', "~> 6.7.1.3"
二、普通的開屏廣告(BUSplashAd展示 + 自定義viewController展示)
1.在APPDelegate 中直接通過BUSplashAd展示,注意這里的??1,2,3,為重要的配置
// 啟動(dòng)頁
- (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.??@"穿山甲廣告官網(wǎng)生成的應(yīng)用ID"
configuration.appID = [BUDAdManager appKey];
configuration.privacyProvider = [[BUDPrivacyProvider alloc] init];
configuration.appLogoImage = [UIImage imageNamed:@"AppIcon"];
configuration.debugLog = @(1);
// 如果使用聚合維度功能,則務(wù)必將以下字段設(shè)置為YES
// 并檢查工程有引用CSJMediation.framework,這樣SDK初始化時(shí)將啟動(dòng)聚合相關(guān)必要組件
configuration.useMediation = NO;
// 聚合廣告的設(shè)置,開屏廣告可配置,也可不配置
[self useMediationSettings];
[BUAdSDKManager startWithAsyncCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
// 聚合維度首次預(yù)緩存,開屏廣告可有可無
// [self useMediationPreload];
// 2.????這里是開屏廣告的配置
[self addSplashAD];
// 這里是廣告的一些測試工具,可有可無
[self configDemo];
// Setup live stream ad
});
}
}];
// [self playerCoustomAudio];
// ??3.這個(gè)的配置需要開啟IDFA
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self requestIDFATracking];
});
}
// 獲取本機(jī)IDFA配置
- (void)requestIDFATracking {
if (@available(iOS 14, *)) {
// iOS14及以上版本需要先請求權(quán)限
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// 獲取到權(quán)限后,依然使用老方法獲取idfa
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"%@",idfa);
} else {
NSLog(@"請?jiān)谠O(shè)置-隱私-跟蹤中允許App請求跟蹤");
}
}];
} else {
// iOS14以下版本依然使用老方法
// 判斷在設(shè)置-隱私里用戶是否打開了廣告跟蹤
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"%@",idfa);
} else {
NSLog(@"請?jiān)谠O(shè)置-隱私-廣告中打開廣告跟蹤功能");
}
}
}
#pragma mark - 開屏廣告相關(guān)的配置
- (void)addSplashAD {
CGRect frame = [UIScreen mainScreen].bounds;
self.startTime = CACurrentMediaTime();
// ??穿山甲開屏廣告代碼位id,官網(wǎng)上通過APPKey申請的廣告位id,一般新建的廣告位半個(gè)小時(shí)至1小時(shí)后可測
BUSplashAd *splashAd = [[BUSplashAd alloc] initWithSlotID:express_splash_ID adSize:frame.size];
splashAd.supportCardView = YES;
splashAd.supportZoomOutView = YES;
// 不支持中途更改代理,中途更改代理會(huì)導(dǎo)致接收不到廣告相關(guān)回調(diào),如若存在中途更改代理場景,需自行處理相關(guān)邏輯,確保廣告相關(guān)回調(diào)正常執(zhí)行。
splashAd.delegate = self;
// ??cardDelegate,zoomOutDelegate在配置了點(diǎn)睛的時(shí)候需要
splashAd.cardDelegate = self;
splashAd.zoomOutDelegate = self;
// ??設(shè)置開屏的廣告顯示時(shí)間
splashAd.tolerateTimeout = 3;
/***
廣告加載成功的時(shí)候,會(huì)立即渲染W(wǎng)KWebView。
如果想預(yù)加載的話,建議一次最多預(yù)加載三個(gè)廣告,如果超過3個(gè)會(huì)很大概率導(dǎo)致WKWebview渲染失敗。
*/
self.splashAd = splashAd;
[self.splashAd loadAdData];
}
#pragma mark -- BUMSplashAdDelegate代理方法
// 開屏成功調(diào)用
- (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當(dāng)前的報(bào)錯(cuò)信息為:%@",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當(dāng)前的報(bào)錯(cuò)信息為:%@",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:@""];
}
// 廣告位點(diǎn)擊
- (void)splashAdDidClick:(nonnull BUSplashAd *)splashAd {
[self pbu_logWithSEL:_cmd msg:@""];
}
// 廣告位關(guān)閉
- (void)splashAdDidClose:(nonnull BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
[self pbu_logWithSEL:_cmd msg:@""];
}
2.使用viewController切換控制器展示
首先要建立一個(gè)自定義的廣告類BUDSplashContainerViewController,這里直接用了官方demo中的實(shí)體類進(jìn)行了修改。
2.1 AppDelegate.m文件
//引用
// BUDSplashContainerViewController可以仿照官網(wǎng)demo里BUDSplashContainerViewController重新寫,這里直接拿了改造
#import "BUDSplashContainerViewController.h"
property (nonatomic, strong) BUSplashAd *splashAd;
@property (nonatomic, strong) BUDSplashContainerViewController *customSplashVC;
// 啟動(dòng)頁空白的問題
@property (nonatomic, strong) UIWindow * adWindow;
//啟動(dòng)頁
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 系統(tǒng)的啟動(dòng)頁-- 延遲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>
// 成功的回調(diào)
- (void)containSplashAdLoadSuccess:(BUSplashAd *)splashAd;
- (void)containSplashAdRenderSuccess:(BUSplashAd *)splashAd;
// 失敗回調(diào)
- (void)containSplashAdFailure:(BUSplashAd *)splashAd error:(BUAdError * _Nullable)error ;
// 定時(shí)器結(jié)束的回調(diào)
- (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;
//??自定義的倒計(jì)時(shí)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(@"這里的定時(shí)器還在跑呀?。?!");
weakSelf.remainingTime--; // 減少剩余時(shí)間
NSString * countDownTitle = [NSString stringWithFormat:@"跳過 %ld", (long)weakSelf.remainingTime];
[weakSelf.countDownButton setTitle:countDownTitle forState:UIControlStateNormal];
if (weakSelf.remainingTime <= 0) {
[weakSelf.countDownTimer invalidate]; // 停止定時(shí)器
[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;
// 不支持中途更改代理,中途更改代理會(huì)導(dǎo)致接收不到廣告相關(guān)回調(diào),如若存在中途更改代理場景,需自行處理相關(guān)邏輯,確保廣告相關(guān)回調(diào)正常執(zhí)行。
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當(dāng)前的報(bào)錯(cuò)信息為:%@",msgResult);
if ([self.delegate respondsToSelector:@selector(containSplashAdFailure:error:)]) {
[self.delegate containSplashAdFailure:splashAd error:error];
}
}
- (void)countDownButtonAction {
NSLog(@"點(diǎn)擊自定義跳過的按鈕呀!??!");
// [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];
//
// ????這個(gè)位置加載自定義的跳過按鈕
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];
// 設(shè)置字體顏色,背景色圓角
[ 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];
// 開啟倒計(jì)時(shí):
[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當(dāng)前的報(bào)錯(cuò)信息為:%@",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);
}
三、自定義點(diǎn)睛的開屏廣告
(具體代碼見上面的:BUDSplashContainerViewController.h .m文件)
3.1設(shè)置點(diǎn)睛的時(shí)候,需要在 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;
// 不支持中途更改代理,中途更改代理會(huì)導(dǎo)致接收不到廣告相關(guān)回調(diào),如若存在中途更改代理場景,需自行處理相關(guān)邏輯,確保廣告相關(guān)回調(diào)正常執(zhí)行。
splashAd.delegate = self;
splashAd.cardDelegate = self;
splashAd.zoomOutDelegate = self;
splashAd.tolerateTimeout = 3;
// 是否設(shè)置點(diǎn)睛的效果
splashAd.hideSkipButton = YES;
[splashAd loadAdData];
self.splashAd = splashAd;
}
3.2需要在代理方法中添加自定義的跳過按鈕
- (void)splashAdRenderSuccess:(BUSplashAd *)splashAd {
// ????這個(gè)位置加載自定義的跳過按鈕
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];
// 設(shè)置字體顏色,背景色圓角
[ 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];
// 開啟倒計(jì)時(shí):
[self startCountdown];
}
}
3.3開屏廣告出現(xiàn)白屏的問題及解決方法
在進(jìn)入界面的時(shí)候,用閃屏頁來打底,設(shè)置閃屏頁顯示的時(shí)間,抵消掉白屏
將廣告層vc添加到新的adWindow上,并將adWindow置頂。
在createSlashVC中修改:
@interface AppDelegate ()
// 新建一個(gè)新的window層
@property (nonatomic, strong) UIWindow * adWindow;
@end
// 修改方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 系統(tǒng)的啟動(dòng)頁-- 延遲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(@"配置的廣告開始展示了");
}
// 開屏廣告結(jié)束后,進(jìn)入APP首頁吧
- (void)containSplashAdLoadSuccess:(BUSplashAd *)splashAd {
NSLog(@"成功結(jié)束1");
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
- (void)containSplashAdRenderSuccess:(BUSplashAd *)splashAd {
NSLog(@"成功結(jié)束22222");
self.adWindow.hidden = YES;
self.adWindow = nil;
self.window.hidden = NO;
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
}
// 定時(shí)器結(jié)束的回調(diào)
- (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];
}
}
四、遇到的一些報(bào)錯(cuò)日志記錄
4.1 線上環(huán)境需要?jiǎng)?chuàng)建一個(gè)線上的APPKey,然后再創(chuàng)建一個(gè)線上的廣告位,在測試的時(shí)候,需要及時(shí)的和官方的客服進(jìn)行聯(lián)系,那邊會(huì)給你開啟應(yīng)用id的白名單,開啟代碼位的白名單,方便開發(fā)測試。
4.2 報(bào)錯(cuò)日志記錄:20001-112;20001-202;20001-228......
這種20001開頭的報(bào)錯(cuò)日志,基本上都是你的應(yīng)用id沒有開啟白名單功能,可以在官網(wǎng)聯(lián)系人工客服,讓他們給你的應(yīng)用id開啟白名單功能,然后你就可以在官網(wǎng)的demo首頁,Tools--Test Measurement---穿山甲廣告預(yù)覽管理自己的廣告id了。
????測試的時(shí)候,要打開“全局廣告預(yù)覽模式”的開關(guān)。
官方demo中選中 Tool -- Test Measurement 打開按鈕
如圖所示:

4.3 20001-101問題:需要官方客服幫忙把廣告位代碼id開啟白名單功能,避免測試多次后,廣告報(bào)錯(cuò)的問題。
基本上需要自己主動(dòng)聯(lián)系穿山甲的官方人工客服,說明你遇到的問題。
一定要切記,聯(lián)系人工客服,人工客服,人工客服!
一定要切記,聯(lián)系人工客服,人工客服,人工客服!
一定要切記,聯(lián)系人工客服,人工客服,人工客服!
五、關(guān)于上線AppStore遇到的問題
問題描述:你的App 包含NSUserTrackingUsageDescription,這表示它可能會(huì)請求追蹤用戶。要提交以供審核,請更新你的App隱私答復(fù)以注明從此App中收集的數(shù)據(jù)將用于追蹤目的,或者
綜合 更新你的 App二進(jìn)制文件并上傳新的構(gòu)建版本。了解更多
首先保證代碼里,infoPlist中設(shè)置了NSUserTrackingUsageDescription;然后在APP上架的界面,找到APP隱私模塊,設(shè)置對應(yīng)的廣告數(shù)據(jù)隱私追蹤即可。
???? APP上線后觀察:
1.廣告打開后,有概率性還會(huì)出現(xiàn)先進(jìn)入APP首頁,然后再進(jìn)入穿山甲的廣告界面。這里的處理,不知道是不是SDK請求廣告資源有延遲的原因,后續(xù)還得繼續(xù)看看其他的處理方法。
2.部分機(jī)型每次打開APP進(jìn)入首頁,看不到穿山甲廣告,打印日志如下:
請求失敗報(bào)錯(cuò)日志:20001-101:沒有匹配到合適的廣告導(dǎo)致請求沒有廣告填充,一般在剛起量時(shí)較為常見,隨著起量以及模型正確預(yù)估可緩解此問題;同時(shí)可降低廣告請求的頻率來緩解此問題。
根據(jù)穿山甲工單解釋,應(yīng)該是我們后臺配置的廣告位,都是一些主流的廣告,請求次數(shù)過多,就會(huì)有限流的問題。所以展示不出來,也沒有合理的解決方案。
報(bào)錯(cuò)日志如下:

3.部分機(jī)型每日接收廣告顯示,大概是3--5次每天。就會(huì)接受不到穿山甲的廣告了。這個(gè)是正常的現(xiàn)象,同一機(jī)型,每天的廣告展示是有限制的。
六、相關(guān)的參考文檔
穿山甲官網(wǎng)幫助文檔
穿山甲官網(wǎng)iOS集成文檔