FqToPONInterstitialAd.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // FqToPONInterstitialAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/5/11.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqToPONInterstitialAd.h"
  9. #import <AnyThinkInterstitial/AnyThinkInterstitial.h>
  10. #import "XSNetwork.h"
  11. #import "GMTools.h"
  12. @interface FqToPONInterstitialAd()<ATInterstitialDelegate>
  13. @property(nonatomic,assign)BOOL isAdReadly;
  14. @property(nonatomic,strong)void(^InterstitialAdCallback)(BOOL);
  15. @end
  16. @implementation FqToPONInterstitialAd
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.agentName = @"TopOn"; //平台名称
  20. self.adUnitId = @"Interstitial";
  21. self.type = @"Interstitial"; //广告类型
  22. self.isAdReadly = NO;
  23. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  24. if ([infos objectForKey:@"topon-Interstitial-unitId"]) {
  25. self.adUnitId = [infos objectForKey:@"topon-Interstitial-unitId"]; //广告组ID
  26. }
  27. //1.程序启动时,加载广告.
  28. [self loadInterstitialAdWithPlacementId:self.adUnitId];
  29. }
  30. return self;
  31. }
  32. //广告是否准备好
  33. -(BOOL)isAdReadly {
  34. if ([[ATAdManager sharedManager] interstitialReadyForPlacementID:self.adUnitId]) {
  35. return YES;
  36. } else {
  37. return NO;
  38. }
  39. return NO;
  40. }
  41. //打开广告
  42. -(void)openInterstitialAd:(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.InterstitialAdCallback = callback;
  50. //判断广告是否准备好.
  51. if([self isAdReadly]){
  52. //广告准备好,展示广告.
  53. UIViewController *vc = [GMTools getViewControl];
  54. [[ATAdManager sharedManager] showInterstitialWithPlacementID:self.adUnitId inViewController:vc delegate:self];
  55. }else{
  56. //无广告可展示,加载广告.
  57. //PS:重新加载广告,考虑一直广告加载失败的情况,超过3次加载广告失败,不做任何处理.不然会死循环.
  58. [self loadInterstitialAdWithPlacementId:self.adUnitId];
  59. [XSNetwork showHudSuccess:@"广告正在加载中"];
  60. }
  61. }
  62. //加载广告资源
  63. -(void)loadInterstitialAdWithPlacementId:(NSString *)placementId {
  64. [[ATAdManager sharedManager] loadADWithPlacementID:self.adUnitId extra:nil delegate:self];
  65. }
  66. #pragma mark - ===========ATInterstitialDelegate=============
  67. -(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
  68. NSLog(@"Interstitial Demo: didFinishLoadingADWithPlacementID");
  69. }
  70. -(void) didFailToLoadADWithPlacementID:(NSString* )placementID error:(NSError *)error {
  71. NSLog(@"Interstitial Demo: failed to load:%@", error);
  72. self.isAdReadly = NO;
  73. if(self.InterstitialAdCallback){
  74. self.InterstitialAdCallback(self.isAdReadly);
  75. }
  76. }
  77. -(void) interstitialDidShowForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
  78. NSLog(@"FqToPONInterstitialAd.m::interstitialDidShowForPlacementID:%@ extra:%@", placementID, extra);
  79. self.isAdReadly = YES;
  80. if(self.InterstitialAdCallback){
  81. self.InterstitialAdCallback(self.isAdReadly);
  82. }
  83. }
  84. -(void) interstitialFailedToShowForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary *)extra {
  85. NSLog(@"FqToPONInterstitialAd.m::interstitialFailedToShowForPlacementID:%@ error:%@ extra:%@", placementID, error, extra);
  86. }
  87. -(void) interstitialDidFailToPlayVideoForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {
  88. NSLog(@"FqToPONInterstitialAd.m::interstitialDidFailToPlayVideoForPlacementID:%@ error:%@ extra:%@", placementID, error, extra);
  89. }
  90. -(void) interstitialDidStartPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
  91. NSLog(@"FqToPONInterstitialAd.m::interstitialDidStartPlayingVideoForPlacementID:%@ extra:%@", placementID, extra);
  92. }
  93. -(void) interstitialDidEndPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
  94. NSLog(@"FqToPONInterstitialAd.m::interstitialDidEndPlayingVideoForPlacementID:%@ extra:%@", placementID, extra);
  95. }
  96. -(void) interstitialDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
  97. NSLog(@"FqToPONInterstitialAd.m::interstitialDidCloseForPlacementID:%@ extra:%@", placementID, extra);
  98. //广告关闭,重新加载广告.为下次广告展示做准备.
  99. [self loadInterstitialAdWithPlacementId:self.adUnitId];
  100. }
  101. -(void) interstitialDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
  102. NSLog(@"FqToPONInterstitialAd.m::interstitialDidClickForPlacementID:%@ extra:%@", placementID, extra);
  103. }
  104. -(void) interstitialDeepLinkOrJumpForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra result:(BOOL)success {
  105. NSLog(@"FqToPONInterstitialAd.m::interstitialDidClickForPlacementID:%@ extra:%@ success:%@", placementID, extra,success? @"YES":@"NO");
  106. }
  107. @end