123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // FqBUDNewInterstitialAd.m
- // XenonSDK
- //
- // Created by fq on 2021/5/21.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqBUDNewInterstitialAd.h"
- #import "GMTools.h"
- #import "XSNetwork.h"
- @interface FqBUDNewInterstitialAd()<BUNativeExpressFullscreenVideoAdDelegate>
- @property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *InterstitialNewAd;
- @property(nonatomic,assign)BOOL isVideoReadly;
- @property(nonatomic,strong)void(^FullScreenVideoCallback)(BOOL);
- @end
- @implementation FqBUDNewInterstitialAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"ChuanSANJIA"; //平台名称
- self.adUnitId = @"Interstitial";
- self.type = @"Interstitial"; //广告类型
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- self.adUnitId = [infos objectForKey:@"csj-NewInterstitial-unitId"]; //广告组ID
- self.isVideoReadly = NO;
-
- self.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
- self.InterstitialNewAd.delegate = self;
- [self.InterstitialNewAd 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.isVideoReadly;
- }
- //打开全屏广告
- -(void)openNewInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
- self.adId = adName;
- self.FullScreenVideoCallback = callback;
-
- if (self.isVideoReadly) {
- [self showNewInterstitialAd];
-
- //数据上报
- [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.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
- self.InterstitialNewAd.delegate = self;
- [self.InterstitialNewAd loadAdData];
- }
- }
- // important:show的时候会进行WKWebview的渲染,建议一次最多展示三个广告,如果超过3个会很大概率导致WKWebview渲染失败。当然一般情况下全屏视频一次只会show一个
- - (void)showNewInterstitialAd {
- if (self.InterstitialNewAd) {
- UIWindow *keyWindow = [GMTools getKeyWindow];
- [self.InterstitialNewAd 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;
-
-
- }
- - (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.InterstitialNewAd = nil;
- //重新加载广告
- self.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
- self.InterstitialNewAd.delegate = self;
- [self.InterstitialNewAd 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
|