FqGDTExpressInterstitialAd.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // FqGDTExpressInterstitialAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/4/29.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqGDTExpressInterstitialAd.h"
  9. #import "GDTExpressInterstitialAd.h"
  10. #import "GMTools.h"
  11. #import "XSNetwork.h"
  12. @interface FqGDTExpressInterstitialAd()<GDTExpressInterstitialAdDelegate>
  13. @property (nonatomic, strong) GDTExpressInterstitialAd *interstitial;
  14. @property(nonatomic,assign)BOOL isAdReadly; //广告是否准备好
  15. @property(nonatomic,strong)void(^InterstitialAdCallback)(BOOL);
  16. @end
  17. @implementation FqGDTExpressInterstitialAd
  18. -(instancetype)init{
  19. if (self = [super init]) {
  20. self.agentName = @"YLH"; //平台名称
  21. self.adUnitId = @"Interstotal";
  22. self.type = @"Interstotal"; //广告类型
  23. self.isAdReadly = NO;
  24. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  25. if ([infos objectForKey:@"ylh-Interstitial-unitId"]) {
  26. self.adUnitId = [infos objectForKey:@"ylh-Interstitial-unitId"]; //广告组ID
  27. }
  28. if (self.adUnitId.length == 0) {
  29. NSLog(@"【优量汇广告】,error=模板2插屏半屏广告位id为空!!!");
  30. }
  31. //预加载广告资源
  32. [self loadExpressInterstitialAdWithPlacementId:self.adUnitId];
  33. }
  34. return self;
  35. }
  36. //打开广告
  37. -(void)openInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  38. self.adId = adName;
  39. self.InterstitialAdCallback = callback;
  40. if (self.interstitial) {
  41. [self.interstitial loadHalfScreenAd];
  42. }
  43. }
  44. //拉取广告
  45. - (void)loadExpressInterstitialAdWithPlacementId:(NSString *)placementId {
  46. if (placementId.length == 0) {
  47. NSLog(@"[优量汇SDK],模板2插屏半屏广告id为空!!!");
  48. return;
  49. }
  50. if (self.interstitial) {
  51. self.interstitial.delegate = nil;
  52. }
  53. self.interstitial = [[GDTExpressInterstitialAd alloc] initWithPlacementId:placementId];
  54. self.interstitial.delegate = self;
  55. self.interstitial.videoMuted = YES; // 设置视频是否Mute,默认自动播放下静音
  56. self.interstitial.videoAutoPlayOnWWAN = NO; // 设置视频是否在非 WiFi 网络自动播放
  57. //self.interstitial.maxVideoDuration = 30; // 如果需要设置视频最大时长,可以通过这个参数来进行设置
  58. //数据上报
  59. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  60. }
  61. //显示广告
  62. - (void)showInterstitialAd {
  63. UIWindow *fK = [GMTools getKeyWindow];
  64. [self.interstitial presentHalfScreenAdFromRootViewController:fK.rootViewController];
  65. //数据上报
  66. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  67. }
  68. #pragma mark - =========GDTExpressInterstitialAdDelegate===========
  69. /**
  70. * 模板插屏半屏广告加载成功回调
  71. * 当接收服务器返回的广告数据成功且模板渲染成功后调用该函数
  72. */
  73. - (void)expressInterstitialSuccessToLoadAd:(GDTExpressInterstitialAd *)unifiedInterstitial
  74. {
  75. NSLog(@"%s",__FUNCTION__);
  76. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Load Success." ]);
  77. NSLog(@"videoDuration:%lf isVideo: %@", unifiedInterstitial.videoDuration, @(unifiedInterstitial.isVideoAd));
  78. [self showInterstitialAd];
  79. }
  80. /**
  81. * 模板插屏半屏广告预加载失败回调
  82. * 当接收服务器返回的广告数据失败或模板渲染失败后调用该函数
  83. */
  84. - (void)expressInterstitialFailToLoadAd:(GDTExpressInterstitialAd *)unifiedInterstitial error:(NSError *)error
  85. {
  86. NSLog(@"%s",__FUNCTION__);
  87. NSLog(@"interstitial fail to load, Error : %@",error);
  88. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  89. //回调
  90. self.isAdReadly = NO;
  91. if(self.InterstitialAdCallback){
  92. self.InterstitialAdCallback(self.isAdReadly);
  93. }
  94. }
  95. /**
  96. * 模板插屏半屏广告将要展示回调
  97. * 模板插屏半屏广告即将展示回调该函数
  98. */
  99. - (void)expressInterstitialWillPresentScreen:(GDTExpressInterstitialAd *)unifiedInterstitial
  100. {
  101. NSLog(@"%s",__FUNCTION__);
  102. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Going to present." ]);
  103. }
  104. /**
  105. * 模板插屏半屏广告展示失败回调
  106. * 模板插屏半屏展示失败时回调该函数
  107. */
  108. - (void)expressInterstitialFailToPresent:(GDTExpressInterstitialAd *)unifiedInterstitial error:(NSError *)error {
  109. NSLog(@"%s",__FUNCTION__);
  110. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"fail to present." ]);
  111. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  112. self.isAdReadly = NO;
  113. if(self.InterstitialAdCallback){
  114. self.InterstitialAdCallback(self.isAdReadly);
  115. }
  116. }
  117. /**
  118. * 模板插屏半屏广告视图展示成功回调
  119. * 模板插屏半屏广告展示成功回调该函数
  120. */
  121. - (void)expressInterstitialDidPresentScreen:(GDTExpressInterstitialAd *)unifiedInterstitial
  122. {
  123. NSLog(@"%s",__FUNCTION__);
  124. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Success Presented." ]);
  125. self.isAdReadly = YES;
  126. if(self.InterstitialAdCallback){
  127. self.InterstitialAdCallback(self.isAdReadly);
  128. }
  129. }
  130. /**
  131. * 模板插屏半屏广告展示结束回调
  132. * 模板插屏半屏广告展示结束回调该函数
  133. */
  134. - (void)expressInterstitialDidDismissScreen:(GDTExpressInterstitialAd *)unifiedInterstitial
  135. {
  136. NSLog(@"%s",__FUNCTION__);
  137. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Finish Presented." ]);
  138. self.interstitial = nil;
  139. }
  140. /**
  141. * 当点击下载应用时会调用系统程序打开
  142. */
  143. - (void)expressInterstitialWillLeaveApplication:(GDTExpressInterstitialAd *)unifiedInterstitial
  144. {
  145. NSLog(@"%s",__FUNCTION__);
  146. NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Application enter background." ]);
  147. }
  148. /**
  149. * 模板插屏半屏广告曝光回调
  150. */
  151. - (void)expressInterstitialWillExposure:(GDTExpressInterstitialAd *)expressInterstitial
  152. {
  153. NSLog(@"%s",__FUNCTION__);
  154. }
  155. /**
  156. * 模板插屏半屏广告点击回调
  157. */
  158. - (void)expressInterstitialClicked:(GDTExpressInterstitialAd *)unifiedInterstitial
  159. {
  160. NSLog(@"%s",__FUNCTION__);
  161. //数据上报
  162. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  163. }
  164. /**
  165. * 点击模板插屏半屏广告以后即将弹出全屏广告页
  166. */
  167. - (void)expressInterstitialAdWillPresentFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial
  168. {
  169. NSLog(@"%s",__FUNCTION__);
  170. }
  171. /**
  172. * 点击模板插屏半屏广告以后弹出全屏广告页
  173. */
  174. - (void)expressInterstitialAdDidPresentFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial
  175. {
  176. NSLog(@"%s",__FUNCTION__);
  177. }
  178. /**
  179. * 全屏广告页将要关闭
  180. */
  181. - (void)expressInterstitialAdWillDismissFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial
  182. {
  183. NSLog(@"%s",__FUNCTION__);
  184. }
  185. /**
  186. * 全屏广告页被关闭
  187. */
  188. - (void)expressInterstitialAdDidDismissFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial
  189. {
  190. NSLog(@"%s",__FUNCTION__);
  191. }
  192. /**
  193. * 模板插屏半屏视频广告 player 播放状态更新回调
  194. */
  195. - (void)expressInterstitialAd:(GDTExpressInterstitialAd *)unifiedInterstitial playerStatusChanged:(GDTMediaPlayerStatus)status
  196. {
  197. NSLog(@"%s",__FUNCTION__);
  198. }
  199. /**
  200. * 模板插屏半屏视频广告详情页 WillPresent 回调
  201. */
  202. - (void)expressInterstitialAdViewWillPresentVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial
  203. {
  204. NSLog(@"%s",__FUNCTION__);
  205. }
  206. /**
  207. * 模板插屏半屏视频广告详情页 DidPresent 回调
  208. */
  209. - (void)expressInterstitialAdViewDidPresentVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial
  210. {
  211. NSLog(@"%s",__FUNCTION__);
  212. }
  213. /**
  214. * 模板插屏半屏视频广告详情页 WillDismiss 回调
  215. */
  216. - (void)expressInterstitialAdViewWillDismissVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial
  217. {
  218. NSLog(@"%s",__FUNCTION__);
  219. }
  220. /**
  221. * 模板插屏半屏视频广告详情页 DidDismiss 回调
  222. */
  223. - (void)expressInterstitialAdViewDidDismissVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial
  224. {
  225. NSLog(@"%s",__FUNCTION__);
  226. }
  227. @end