FqGDTSplashAd.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // FqGDTSplashAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/4/29.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqGDTSplashAd.h"
  9. #import "GDTSplashAd.h"
  10. #import "GDTSplashZoomOutView.h"
  11. #import "GDTSplashZoomOutView+GDTDraggable.h"
  12. #import "XSNetwork.h"
  13. #import "GMTools.h"
  14. @interface FqGDTSplashAd()<GDTSplashAdDelegate,GDTSplashZoomOutViewDelegate>
  15. @property (strong, nonatomic) GDTSplashAd *splashAd;
  16. @property(nonatomic,assign)BOOL isAdReadly; //广告是否准备好
  17. @property (retain, nonatomic) UIView *bottomView;
  18. @property (nonatomic, assign) BOOL isParallelLoad;
  19. @property (nonatomic, assign) BOOL supportZoomoutView; //视频V+
  20. @property(nonatomic,strong)void(^splashAdCallback)(BOOL);
  21. @end
  22. @implementation FqGDTSplashAd
  23. -(instancetype)init{
  24. if (self = [super init]) {
  25. self.agentName = @"YLH"; //平台名称
  26. self.adUnitId = @"splash";
  27. self.type = @"splash"; //广告类型
  28. self.isAdReadly = NO;
  29. self.isParallelLoad = NO;
  30. self.supportZoomoutView = NO;
  31. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  32. if ([infos objectForKey:@"ylh-splash-unitId"]) {
  33. self.adUnitId = [infos objectForKey:@"ylh-splash-unitId"]; //广告组ID
  34. }
  35. //加载广告
  36. [self loadFullscreenAdWithPlacementId:self.adUnitId];
  37. }
  38. return self;
  39. }
  40. //打开广告
  41. -(void)opensplashAd:(NSString *)adName supportZoomoutView:(BOOL)flag callback:(void (^)(BOOL))callback {
  42. if (self.adUnitId.length == 0) {
  43. NSLog(@"【优量汇广告】,error=开屏广告广告位id为空!!!");
  44. return;
  45. }
  46. self.adId = adName;
  47. self.supportZoomoutView = flag;
  48. self.splashAd.needZoomOut = self.supportZoomoutView;
  49. self.splashAdCallback = callback;
  50. if (self.splashAd) {
  51. [self.splashAd loadFullScreenAd];
  52. }
  53. }
  54. ///拉取广告
  55. - (void)loadFullscreenAdWithPlacementId:(NSString *)placementId {
  56. if (placementId.length == 0) {
  57. NSLog(@"优量汇开屏广告位id为空!!!");
  58. return;
  59. }
  60. self.isParallelLoad = YES;
  61. self.splashAd = [[GDTSplashAd alloc] initWithPlacementId:placementId];
  62. self.splashAd.delegate = self;
  63. self.splashAd.fetchDelay = 5;
  64. // UIImage *splashImage = [UIImage imageNamed:@"SplashNormal"];
  65. // if ([self isIPhoneXSeries]) {
  66. // splashImage = [UIImage imageNamed:@"SplashX"];
  67. // } else if ([UIScreen mainScreen].bounds.size.height == 480) {
  68. // splashImage = [UIImage imageNamed:@"SplashSmall"];
  69. // }
  70. self.splashAd.needZoomOut = self.supportZoomoutView;
  71. // self.splashAd.backgroundImage = splashImage;
  72. self.splashAd.backgroundImage.accessibilityIdentifier = @"splash_ad";
  73. //预加载广告资源.
  74. [self.splashAd loadFullScreenAd];
  75. //数据上报
  76. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  77. }
  78. ///展示广告
  79. - (void)showFullscreenAd {
  80. if (!self.isParallelLoad) return;
  81. if (self.splashAd.isAdValid) {
  82. UIWindow *fK = [GMTools getKeyWindow];
  83. [self.splashAd showFullScreenAdInWindow:fK withLogoImage:nil skipView:nil];
  84. //数据上报
  85. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  86. }
  87. }
  88. #pragma mark - =======GDTSplashAdDelegate========
  89. //广告素材加载成功
  90. -(void)splashAdDidLoad:(GDTSplashAd *)splashAd {
  91. if (splashAd.splashZoomOutView) {
  92. UIWindow *fK = [GMTools getKeyWindow];
  93. UIViewController *vc = fK.rootViewController;
  94. [vc.view addSubview:splashAd.splashZoomOutView];
  95. splashAd.splashZoomOutView.rootViewController = vc;
  96. // 支持拖拽
  97. [splashAd.splashZoomOutView supportDrag];
  98. }
  99. NSLog(@"%s", __func__);
  100. NSLog(@"广告拉取成功");
  101. NSLog(@"ecpmLevel:%@", splashAd.eCPMLevel);
  102. //广告拉取成功, 展示广告.
  103. [self showFullscreenAd];
  104. }
  105. -(void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd
  106. {
  107. NSLog(@"%s",__FUNCTION__);
  108. NSLog(@"广告展示成功");
  109. self.isAdReadly = YES;
  110. if(self.splashAdCallback){
  111. self.splashAdCallback(self.isAdReadly);
  112. }
  113. }
  114. //加载失败
  115. -(void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
  116. {
  117. NSLog(@"%s%@",__FUNCTION__,error);
  118. //self.splashAd = nil;
  119. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  120. if (self.isParallelLoad) {
  121. NSLog(@"广告展示失败");
  122. }else{
  123. NSLog(@"广告拉取失败");
  124. }
  125. self.isAdReadly = NO;
  126. if(self.splashAdCallback){
  127. self.splashAdCallback(self.isAdReadly);
  128. }
  129. }
  130. - (void)splashAdWillClosedBeforeClick:(GDTSplashAd *)splashAd {
  131. }
  132. - (void)splashAdDidClosedBeforeClick:(GDTSplashAd *)splashAd {
  133. }
  134. - (void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd
  135. {
  136. NSLog(@"%s",__FUNCTION__);
  137. }
  138. - (void)splashAdWillClosed:(GDTSplashAd *)splashAd
  139. {
  140. NSLog(@"%s",__FUNCTION__);
  141. }
  142. -(void)splashAdClosed:(GDTSplashAd *)splashAd
  143. {
  144. //数据上报
  145. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  146. NSLog(@"%s",__FUNCTION__);
  147. self.splashAd = nil;
  148. }
  149. - (void)splashAdWillPresentFullScreenModal:(GDTSplashAd *)splashAd
  150. {
  151. NSLog(@"%s",__FUNCTION__);
  152. }
  153. - (void)splashAdDidPresentFullScreenModal:(GDTSplashAd *)splashAd
  154. {
  155. NSLog(@"%s",__FUNCTION__);
  156. }
  157. - (void)splashAdExposured:(GDTSplashAd *)splashAd
  158. {
  159. NSLog(@"%s",__FUNCTION__);
  160. }
  161. - (void)splashAdClicked:(GDTSplashAd *)splashAd
  162. {
  163. //数据上报
  164. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  165. if (splashAd.splashZoomOutView) {
  166. [splashAd.splashZoomOutView removeFromSuperview];
  167. }
  168. NSLog(@"%s",__FUNCTION__);
  169. }
  170. - (void)splashAdWillDismissFullScreenModal:(GDTSplashAd *)splashAd
  171. {
  172. NSLog(@"%s",__FUNCTION__);
  173. }
  174. - (void)splashAdDidDismissFullScreenModal:(GDTSplashAd *)splashAd
  175. {
  176. NSLog(@"%s",__FUNCTION__);
  177. }
  178. #pragma mark - GDTSplashZoomOutViewDelegate
  179. - (void)splashZoomOutViewDidClick:(GDTSplashZoomOutView *)splashZoomOutView
  180. {
  181. NSLog(@"%s",__FUNCTION__);
  182. }
  183. - (void)splashZoomOutViewAdDidClose:(GDTSplashZoomOutView *)splashZoomOutView
  184. {
  185. NSLog(@"%s",__FUNCTION__);
  186. }
  187. - (void)splashZoomOutViewAdVideoFinished:(GDTSplashZoomOutView *)splashZoomOutView
  188. {
  189. NSLog(@"%s",__FUNCTION__);
  190. }
  191. - (void)splashZoomOutViewAdDidPresentFullScreenModal:(GDTSplashZoomOutView *)splashZoomOutView
  192. {
  193. NSLog(@"%s",__FUNCTION__);
  194. }
  195. - (void)splashZoomOutViewAdDidDismissFullScreenModal:(GDTSplashZoomOutView *)splashZoomOutView
  196. {
  197. NSLog(@"%s",__FUNCTION__);
  198. }
  199. #pragma mark - Private Method
  200. -(BOOL)isIPhoneXSeries {
  201. if (@available(iOS 11.0, *)) {
  202. UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
  203. if (mainWindow.safeAreaInsets.bottom > 0.0) {
  204. return YES;
  205. }
  206. }
  207. return NO;
  208. }
  209. @end