FqBUDFullScreenVideo.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // FqBUDFullScreenVideo.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/4/22.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqBUDFullScreenVideo.h"
  9. #import "GMTools.h"
  10. #import "XSNetwork.h"
  11. @interface FqBUDFullScreenVideo()<BUNativeExpressFullscreenVideoAdDelegate>
  12. @property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *fullscreenAd;
  13. @property(nonatomic,assign)BOOL isVideoReadly;
  14. @property(nonatomic,strong)void(^FullScreenVideoCallback)(BOOL);
  15. @end
  16. @implementation FqBUDFullScreenVideo
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.agentName = @"ChuanSANJIA"; //平台名称
  20. self.adUnitId = @"FullScreenVideo";
  21. self.type = @"FullScreenVideo"; //广告类型
  22. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  23. self.adUnitId = [infos objectForKey:@"csj-fullscreenvideo-unitId"]; //广告组ID
  24. self.isVideoReadly = NO;
  25. self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  26. self.fullscreenAd.delegate = self;
  27. [self.fullscreenAd 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.fullscreenAd;
  36. }
  37. //打开全屏广告
  38. -(void)openFullScreenVideoAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  39. self.adId = adName;
  40. self.FullScreenVideoCallback = callback;
  41. if (self.isVideoReadly) {
  42. [self showFullscreenVideoAd];
  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.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  49. self.fullscreenAd.delegate = self;
  50. [self.fullscreenAd loadAdData];
  51. }
  52. }
  53. // important:show的时候会进行WKWebview的渲染,建议一次最多展示三个广告,如果超过3个会很大概率导致WKWebview渲染失败。当然一般情况下全屏视频一次只会show一个
  54. - (void)showFullscreenVideoAd {
  55. if (self.fullscreenAd) {
  56. UIWindow *keyWindow = [GMTools getKeyWindow];
  57. [self.fullscreenAd 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. // dispatch_async(dispatch_get_main_queue(), ^{
  96. // [self showFullscreenVideoAd];
  97. // });
  98. }
  99. - (void)nativeExpressFullscreenVideoAdWillVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  100. [self pbud_logWithSEL:_cmd msg:@""];
  101. }
  102. - (void)nativeExpressFullscreenVideoAdDidVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  103. [self pbud_logWithSEL:_cmd msg:@""];
  104. }
  105. - (void)nativeExpressFullscreenVideoAdDidClick:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  106. [self pbud_logWithSEL:_cmd msg:@""];
  107. //数据上报
  108. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  109. }
  110. - (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  111. [self pbud_logWithSEL:_cmd msg:@""];
  112. }
  113. - (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  114. [self pbud_logWithSEL:_cmd msg:@""];
  115. //数据上报
  116. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  117. //同一次请求的广告最多只能计一次展示,重复的展示会被系统过滤,看完广告后将原来的广告对象置为nil,保证广告对象为新的请求对象
  118. self.fullscreenAd = nil;
  119. //重新加载广告
  120. self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:self.adUnitId];
  121. self.fullscreenAd.delegate = self;
  122. [self.fullscreenAd loadAdData];
  123. }
  124. - (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
  125. [self pbud_logWithSEL:_cmd msg:@""];
  126. }
  127. - (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
  128. [self pbud_logWithSEL:_cmd msg:@""];
  129. }
  130. - (void)nativeExpressFullscreenVideoAdCallback:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd withType:(BUNativeExpressFullScreenAdType) nativeExpressVideoAdType{
  131. [self pbud_logWithSEL:_cmd msg:@""];
  132. }
  133. - (void)nativeExpressFullscreenVideoAdDidCloseOtherController:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd interactionType:(BUInteractionType)interactionType {
  134. NSString *str;
  135. if (interactionType == BUInteractionTypePage) {
  136. str = @"ladingpage";
  137. } else if (interactionType == BUInteractionTypeVideoAdDetail) {
  138. str = @"videoDetail";
  139. } else {
  140. str = @"appstoreInApp";
  141. }
  142. [self pbud_logWithSEL:_cmd msg:str];
  143. }
  144. #pragma mark - Log
  145. - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
  146. NSLog(@"SDKDemoDelegate BUNativeExpressFullscreenVideoAd In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
  147. }
  148. @end