FqBUDNewInterstitialAd.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // FqBUDNewInterstitialAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/5/21.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqBUDNewInterstitialAd.h"
  9. #import "GMTools.h"
  10. #import "XSNetwork.h"
  11. @interface FqBUDNewInterstitialAd()<BUNativeExpressFullscreenVideoAdDelegate>
  12. @property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *InterstitialNewAd;
  13. @property(nonatomic,assign)BOOL isVideoReadly;
  14. @property(nonatomic,strong)void(^FullScreenVideoCallback)(BOOL);
  15. @end
  16. @implementation FqBUDNewInterstitialAd
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.agentName = @"ChuanSANJIA"; //平台名称
  20. self.adUnitId = @"Interstitial";
  21. self.type = @"Interstitial"; //广告类型
  22. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  23. self.adUnitId = [infos objectForKey:@"csj-NewInterstitial-unitId"]; //广告组ID
  24. self.isVideoReadly = NO;
  25. self.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  26. self.InterstitialNewAd.delegate = self;
  27. [self.InterstitialNewAd loadAdData];
  28. //数据上报后台
  29. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  30. }
  31. return self;
  32. }
  33. //广告是否有效可用
  34. -(BOOL)isAdReady {
  35. return self.isVideoReadly;
  36. }
  37. //打开全屏广告
  38. -(void)openNewInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  39. self.adId = adName;
  40. self.FullScreenVideoCallback = callback;
  41. if (self.isVideoReadly) {
  42. [self showNewInterstitialAd];
  43. //数据上报
  44. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  45. }else{
  46. [XSNetwork showHudFailure:@"广告加载中"];
  47. //加载广告
  48. self.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  49. self.InterstitialNewAd.delegate = self;
  50. [self.InterstitialNewAd loadAdData];
  51. }
  52. }
  53. // important:show的时候会进行WKWebview的渲染,建议一次最多展示三个广告,如果超过3个会很大概率导致WKWebview渲染失败。当然一般情况下全屏视频一次只会show一个
  54. - (void)showNewInterstitialAd {
  55. if (self.InterstitialNewAd) {
  56. UIWindow *keyWindow = [GMTools getKeyWindow];
  57. [self.InterstitialNewAd showAdFromRootViewController:keyWindow.rootViewController];
  58. }
  59. }
  60. #pragma mark - BUNativeExpressFullscreenVideoAdDelegate
  61. - (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  62. [self pbud_logWithSEL:_cmd msg:@""];
  63. NSLog(@"[穿山甲]:全屏广告素材加载成功");
  64. }
  65. - (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
  66. [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]];
  67. NSLog(@"【BUFoundation】FullscreenVideo Request error:%@",error);
  68. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  69. //广告加载失败回调
  70. self.isVideoReadly = NO;
  71. if (self.FullScreenVideoCallback) {
  72. self.FullScreenVideoCallback(self.isVideoReadly);
  73. }
  74. }
  75. - (void)nativeExpressFullscreenVideoAdViewRenderSuccess:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd {
  76. [self pbud_logWithSEL:_cmd msg:@""];
  77. self.isVideoReadly = YES;
  78. if (self.FullScreenVideoCallback) {
  79. self.FullScreenVideoCallback(self.isVideoReadly);
  80. }
  81. }
  82. - (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
  83. [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]];
  84. NSLog(@"【BUFoundation】FullscreenVideo Request error:%@",error);
  85. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  86. self.isVideoReadly = NO;
  87. if (self.FullScreenVideoCallback) {
  88. self.FullScreenVideoCallback(self.isVideoReadly);
  89. }
  90. }
  91. - (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  92. [self pbud_logWithSEL:_cmd msg:@""];
  93. self.isVideoReadly = YES;
  94. }
  95. - (void)nativeExpressFullscreenVideoAdWillVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  96. [self pbud_logWithSEL:_cmd msg:@""];
  97. }
  98. - (void)nativeExpressFullscreenVideoAdDidVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  99. [self pbud_logWithSEL:_cmd msg:@""];
  100. }
  101. - (void)nativeExpressFullscreenVideoAdDidClick:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  102. [self pbud_logWithSEL:_cmd msg:@""];
  103. //数据上报
  104. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  105. }
  106. - (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  107. [self pbud_logWithSEL:_cmd msg:@""];
  108. }
  109. - (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  110. [self pbud_logWithSEL:_cmd msg:@""];
  111. //数据上报
  112. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  113. //同一次请求的广告最多只能计一次展示,重复的展示会被系统过滤,看完广告后将原来的广告对象置为nil,保证广告对象为新的请求对象
  114. self.InterstitialNewAd = nil;
  115. //重新加载广告
  116. self.InterstitialNewAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  117. self.InterstitialNewAd.delegate = self;
  118. [self.InterstitialNewAd loadAdData];
  119. }
  120. - (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  121. [self pbud_logWithSEL:_cmd msg:@""];
  122. }
  123. - (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
  124. [self pbud_logWithSEL:_cmd msg:@""];
  125. }
  126. - (void)nativeExpressFullscreenVideoAdCallback:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd withType:(BUNativeExpressFullScreenAdType) nativeExpressVideoAdType{
  127. [self pbud_logWithSEL:_cmd msg:@""];
  128. }
  129. - (void)nativeExpressFullscreenVideoAdDidCloseOtherController:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd interactionType:(BUInteractionType)interactionType {
  130. NSString *str;
  131. if (interactionType == BUInteractionTypePage) {
  132. str = @"ladingpage";
  133. } else if (interactionType == BUInteractionTypeVideoAdDetail) {
  134. str = @"videoDetail";
  135. } else {
  136. str = @"appstoreInApp";
  137. }
  138. [self pbud_logWithSEL:_cmd msg:str];
  139. }
  140. #pragma mark - Log
  141. - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
  142. NSLog(@"SDKDemoDelegate BUNativeExpressFullscreenVideoAd In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
  143. }
  144. @end