// // FqBUDFullScreenVideo.m // XenonSDK // // Created by fq on 2021/4/22. // Copyright © 2021 SAGESSE. All rights reserved. // #import "FqBUDFullScreenVideo.h" #import "GMTools.h" #import "XSNetwork.h" @interface FqBUDFullScreenVideo() @property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *fullscreenAd; @property(nonatomic,assign)BOOL isVideoReadly; @property(nonatomic,strong)void(^FullScreenVideoCallback)(BOOL); @end @implementation FqBUDFullScreenVideo -(instancetype)init{ if (self = [super init]) { self.agentName = @"ChuanSANJIA"; //平台名称 self.adUnitId = @"FullScreenVideo"; self.type = @"FullScreenVideo"; //广告类型 NSDictionary *infos = [[NSBundle mainBundle] infoDictionary]; self.adUnitId = [infos objectForKey:@"csj-fullscreenvideo-unitId"]; //广告组ID self.isVideoReadly = NO; self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId]; self.fullscreenAd.delegate = self; [self.fullscreenAd loadAdData]; //数据上报后台 [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } return self; } //广告是否有效可用 -(BOOL)isAdReady { return self.fullscreenAd; } //打开全屏广告 -(void)openFullScreenVideoAd:(NSString *)adName callback:(void (^)(BOOL))callback { self.adId = adName; self.FullScreenVideoCallback = callback; if (self.isVideoReadly) { [self showFullscreenVideoAd]; //数据上报 [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; }else{ [XSNetwork showHudFailure:@"广告加载中"]; //加载广告 self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId]; self.fullscreenAd.delegate = self; [self.fullscreenAd loadAdData]; } } // important:show的时候会进行WKWebview的渲染,建议一次最多展示三个广告,如果超过3个会很大概率导致WKWebview渲染失败。当然一般情况下全屏视频一次只会show一个 - (void)showFullscreenVideoAd { if (self.fullscreenAd) { UIWindow *keyWindow = [GMTools getKeyWindow]; [self.fullscreenAd showAdFromRootViewController:keyWindow.rootViewController]; } } #pragma mark - BUNativeExpressFullscreenVideoAdDelegate - (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; NSLog(@"[穿山甲]:全屏广告素材加载成功"); } - (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error { [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]]; NSLog(@"【BUFoundation】FullscreenVideo Request error:%@",error); self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; //广告加载失败回调 self.isVideoReadly = NO; if (self.FullScreenVideoCallback) { self.FullScreenVideoCallback(self.isVideoReadly); } } - (void)nativeExpressFullscreenVideoAdViewRenderSuccess:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; self.isVideoReadly = YES; if (self.FullScreenVideoCallback) { self.FullScreenVideoCallback(self.isVideoReadly); } } - (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error { [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]]; NSLog(@"【BUFoundation】FullscreenVideo Request error:%@",error); self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; self.isVideoReadly = NO; if (self.FullScreenVideoCallback) { self.FullScreenVideoCallback(self.isVideoReadly); } } - (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; self.isVideoReadly = YES; //第二步.显示视频广告 // dispatch_async(dispatch_get_main_queue(), ^{ // [self showFullscreenVideoAd]; // }); } - (void)nativeExpressFullscreenVideoAdWillVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdDidVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdDidClick:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; //数据上报 [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } - (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; //数据上报 [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; //同一次请求的广告最多只能计一次展示,重复的展示会被系统过滤,看完广告后将原来的广告对象置为nil,保证广告对象为新的请求对象 self.fullscreenAd = nil; //重新加载广告 self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId]; self.fullscreenAd.delegate = self; [self.fullscreenAd loadAdData]; } - (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd { [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error { [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdCallback:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd withType:(BUNativeExpressFullScreenAdType) nativeExpressVideoAdType{ [self pbud_logWithSEL:_cmd msg:@""]; } - (void)nativeExpressFullscreenVideoAdDidCloseOtherController:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd 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]; } #pragma mark - Log - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg { NSLog(@"SDKDemoDelegate BUNativeExpressFullscreenVideoAd In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg); } @end