FqToPONSplashAd.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // FqToPONSplashAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/5/11.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqToPONSplashAd.h"
  9. #import <AnyThinkSDK/AnyThinkSDK.h>
  10. #import <AnyThinkSplash/AnyThinkSplash.h>
  11. #import "XSNetwork.h"
  12. @interface FqToPONSplashAd()<ATSplashDelegate>
  13. @property(nonatomic,assign)BOOL isAdReadly;
  14. @property(nonatomic,strong)void(^splashAdCallback)(BOOL);
  15. @end
  16. @implementation FqToPONSplashAd
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.agentName = @"TopOn"; //平台名称
  20. self.adUnitId = @"splash";
  21. self.type = @"splash"; //广告类型
  22. self.isAdReadly = NO;
  23. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  24. if ([infos objectForKey:@"topon-splash-unitId"]) {
  25. self.adUnitId = [infos objectForKey:@"topon-splash-unitId"]; //广告组ID
  26. }
  27. //1.程序启动时,加载广告.
  28. [self loadSplashAdWithPlacementId:self.adUnitId];
  29. }
  30. return self;
  31. }
  32. //广告是否准备好
  33. -(BOOL)isAdReadly {
  34. if ([[ATAdManager sharedManager] splashReadyForPlacementID:self.adUnitId]) {
  35. return YES;
  36. } else {
  37. return NO;
  38. }
  39. return NO;
  40. }
  41. //用户点击打开广告
  42. -(void)opensplashAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  43. if (self.adUnitId.length == 0) {
  44. NSLog(@"【ToPon广告】,error=开屏广告广告位id为空!!!");
  45. //[XSNetwork showHudFailure:@"广告位id为空!"];
  46. return;
  47. }
  48. self.adId = adName;
  49. self.splashAdCallback = callback;
  50. //判断广告是否准备好.
  51. if([self isAdReadly]){
  52. //广告准备好,展示广告.
  53. UIWindow *mainWindow = nil;
  54. if (@available(iOS 13.0, *)) {
  55. mainWindow = [UIApplication sharedApplication].windows.firstObject;
  56. [mainWindow makeKeyWindow];
  57. }else {
  58. mainWindow = [UIApplication sharedApplication].keyWindow;
  59. }
  60. [[ATAdManager sharedManager] showSplashWithPlacementID:self.adUnitId window:mainWindow delegate:self];
  61. }else{
  62. //无广告可展示,加载广告.
  63. //PS:重新加载广告,考虑一直广告加载失败的情况,超过3次加载广告失败,不做任何处理.不然会死循环.
  64. [self loadSplashAdWithPlacementId:self.adUnitId];
  65. [XSNetwork showHudSuccess:@"广告正在加载中"];
  66. }
  67. }
  68. -(void)loadSplashAdWithPlacementId:(NSString *)placementId {
  69. //containerView:自定义的开屏label
  70. [[ATAdManager sharedManager] loadADWithPlacementID:placementId extra:@{kATSplashExtraTolerateTimeoutKey:@5.5} delegate:self containerView:nil];
  71. }
  72. #pragma mark - ===========ATSplashDelegate============
  73. - (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
  74. NSLog(@"Splash Demo: didFinishLoadingADWithPlacementID");
  75. }
  76. - (void)didFailToLoadADWithPlacementID:(NSString* )placementID error:(NSError *)error {
  77. NSLog(@"Splash Demo: failed to load:%@", error);
  78. self.isAdReadly = NO;
  79. if(self.splashAdCallback){
  80. self.splashAdCallback(self.isAdReadly);
  81. }
  82. }
  83. #pragma mark - AT Splash Delegate method(s)
  84. - (void)splashDidShowForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
  85. NSLog(@"FqToPONSplashAd.m::splashDidShowForPlacementID:%@ extra:%@", placementID, extra);
  86. self.isAdReadly = YES;
  87. if(self.splashAdCallback){
  88. self.splashAdCallback(self.isAdReadly);
  89. }
  90. }
  91. - (void)splashDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
  92. NSLog(@"FqToPONSplashAd.m::splashDidClickForPlacementID:%@ extra:%@", placementID, extra);
  93. }
  94. - (void)splashDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
  95. NSLog(@"FqToPONSplashAd.m::splashDidCloseForPlacementID:%@ extra:%@", placementID, extra);
  96. //广告关闭,重新加载广告.为下次广告展示做准备.
  97. [self loadSplashAdWithPlacementId:self.adUnitId];
  98. }
  99. - (void)splashDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
  100. }
  101. - (void)splashZoomOutViewDidClickForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
  102. }
  103. - (void)splashZoomOutViewDidCloseForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
  104. }
  105. @end