TOPONAdManager.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // TOPONAdManager.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/5/11.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "TOPONAdManager.h"
  9. #import <AnyThinkSDK/AnyThinkSDK.h>
  10. #import <AppTrackingTransparency/AppTrackingTransparency.h>
  11. #import "XSNetwork.h"
  12. #import "FqToPONSplashAd.h"
  13. #import "FqToPONInterstitialAd.h"
  14. #import "FqToPONRewardedVideoAd.h"
  15. #import "FqToPONBannerAd.h"
  16. #import "FqToPONExpressNativeAd.h"
  17. @interface TOPONAdManager()
  18. //开屏广告
  19. @property(nonatomic,strong)FqToPONSplashAd *splashAd;
  20. //插屏广告
  21. @property(nonatomic,strong)FqToPONInterstitialAd *interstitialAd;
  22. //视频激励广告
  23. @property(nonatomic,strong)FqToPONRewardedVideoAd *rewardVideoAd;
  24. //横幅广告
  25. @property(nonatomic,strong)FqToPONBannerAd *bannerAd;
  26. //原生广告
  27. @property(nonatomic,strong)FqToPONExpressNativeAd *nativeAd;
  28. @end
  29. @implementation TOPONAdManager
  30. + (instancetype)sharedInstance{
  31. return [[super alloc]init];
  32. }
  33. + (instancetype)allocWithZone:(struct _NSZone *)zone {
  34. static TOPONAdManager *instance;
  35. static dispatch_once_t onceToken;
  36. dispatch_once(&onceToken, ^{
  37. instance = [super allocWithZone:zone];
  38. #if DEBUG
  39. //...
  40. #endif
  41. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  42. NSString *topOnAppId = [infos objectForKey:@"topOnAppId"];
  43. NSString *appKey = [infos objectForKey:@"topOnAppKey"];
  44. if (topOnAppId.length == 0) {
  45. NSLog(@"【TopOn广告】,error=应用ID为空!!");
  46. [XSNetwork showHudFailure:@"TopOn:应用ID为空"];
  47. topOnAppId = @"";
  48. }else if (appKey.length == 0){
  49. NSLog(@"【TopOn广告】,error=appKey为空!!");
  50. [XSNetwork showHudFailure:@"TopOn:appKey为空"];
  51. }else{
  52. [ATAPI setLogEnabled:YES];
  53. //iOS14.5 数据跟踪,需要征求用户同意弹窗.
  54. if (@available(iOS 14, *)) {
  55. [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
  56. [[ATAPI sharedInstance] startWithAppID:topOnAppId appKey:appKey error:nil];
  57. }];
  58. }else{
  59. [[ATAPI sharedInstance] startWithAppID:topOnAppId appKey:appKey error:nil];
  60. }
  61. #if DEBUG
  62. [ATAPI integrationChecking];
  63. #endif
  64. instance.splashAd = [[FqToPONSplashAd alloc]init]; //开屏广告
  65. instance.interstitialAd = [[FqToPONInterstitialAd alloc]init]; //插屏广告
  66. instance.rewardVideoAd = [[FqToPONRewardedVideoAd alloc]init]; //视频激励广告
  67. instance.bannerAd = [[FqToPONBannerAd alloc]init]; //横幅广告
  68. instance.nativeAd = [[FqToPONExpressNativeAd alloc]init]; //原生广告
  69. }
  70. });
  71. return instance;
  72. }
  73. -(void)opensplashAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  74. [self.splashAd opensplashAd:adName callback:callback];
  75. }
  76. -(void)openInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  77. [self.interstitialAd openInterstitialAd:adName callback:callback];
  78. }
  79. -(void)openRewardedVideoAd:(NSString *)adName callback:(void (^)(BOOL,BOOL))callback {
  80. [self.rewardVideoAd openRewardedVideoAd:adName callback:callback];
  81. }
  82. -(void)openExpressBannerAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  83. [self.bannerAd openBannerAd:adName callback:callback];
  84. }
  85. -(void)openNativeAdWithX:(int)x Y:(int)y width:(int)w height:(int)h adId:(NSString *)adName callback:(void (^)(BOOL))callback {
  86. [self.nativeAd openNativeAdWithX:x Y:y width:w height:h adId:adName callback:callback];
  87. }
  88. @end