MLAdManager.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // MLAdManager.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/4/21.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "MLAdManager.h"
  9. #import "FqAdsplashAdView.h"
  10. #import "FqBUDFullScreenVideo.h"
  11. #import "FqBUDExpressInterstitial.h"
  12. #import "FqBUDExpressRewardedVideo.h"
  13. #import "FqBUDNativeExpressBanner.h"
  14. #import "FqBUDExpressNativeAd.h"
  15. #import "FqBUDNewInterstitialAd.h"
  16. #import <AppTrackingTransparency/AppTrackingTransparency.h>
  17. @interface MLAdManager()
  18. @property(nonatomic,strong)FqAdsplashAdView *splashview;
  19. @property(nonatomic,strong)FqBUDFullScreenVideo *fullscreenVideo;
  20. @property(nonatomic,strong)FqBUDExpressInterstitial *interstitialAd;
  21. @property(nonatomic,strong)FqBUDNewInterstitialAd *interstitialNewAd;
  22. @property(nonatomic,strong)FqBUDExpressRewardedVideo *rewardedVideo;
  23. @property(nonatomic,strong)FqBUDNativeExpressBanner *nativeBanner;
  24. @property(nonatomic,strong)FqBUDExpressNativeAd *nativeAd;
  25. @end
  26. @implementation MLAdManager
  27. #pragma mark - 单利 懒加载
  28. + (instancetype)sharedInstance{
  29. return [[super alloc]init];
  30. }
  31. + (instancetype)allocWithZone:(struct _NSZone *)zone {
  32. static MLAdManager *instance;
  33. static dispatch_once_t onceToken;
  34. dispatch_once(&onceToken, ^{
  35. instance = [super allocWithZone:zone];
  36. NSInteger territory = [[NSUserDefaults standardUserDefaults]integerForKey:@"territory"];
  37. BOOL isNoCN = (territory>0&&territory!=BUAdSDKTerritory_CN);
  38. ///optional
  39. ///CN china, NO_CN is not china
  40. ///you must set Territory first, if you need to set them
  41. [BUAdSDKManager setTerritory:isNoCN?BUAdSDKTerritory_NO_CN:BUAdSDKTerritory_CN];
  42. //[BUAdSDKManager setGDPR:0];
  43. [BUAdSDKManager setCoppa:0];
  44. #if DEBUG
  45. [BUAdSDKManager setLoglevel:BUAdSDKLogLevelDebug];
  46. #endif
  47. //BUAdSDK requires iOS 9 and up
  48. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  49. NSString *csjAppId = [infos objectForKey:@"csjAppId"];
  50. if (csjAppId.length == 0) {
  51. NSLog(@"【穿山甲广告】,error=应用ID为空!!");
  52. csjAppId = @"";
  53. }else{
  54. //iOS14.5 数据跟踪,需要征求用户同意弹窗.
  55. if (@available(iOS 14, *)) {
  56. [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
  57. [BUAdSDKManager setAppID:csjAppId];
  58. }];
  59. }else{
  60. [BUAdSDKManager setAppID:csjAppId];
  61. }
  62. [BUAdSDKManager setIsPaidApp:NO];
  63. instance.splashview = [[FqAdsplashAdView alloc]init]; //1.开屏广告
  64. instance.fullscreenVideo = [[FqBUDFullScreenVideo alloc]init]; //2.全屏广告
  65. instance.interstitialAd = [[FqBUDExpressInterstitial alloc]init]; //3.插页广告
  66. instance.interstitialNewAd = [[FqBUDNewInterstitialAd alloc]init]; //新插屏广告
  67. instance.rewardedVideo = [[FqBUDExpressRewardedVideo alloc]init]; //4.视频激励广告
  68. instance.nativeBanner = [[FqBUDNativeExpressBanner alloc]init]; //5.原生(模板)横幅广告
  69. instance.nativeAd = [[FqBUDExpressNativeAd alloc]init]; //6.原生(模板)广告
  70. }
  71. });
  72. return instance;
  73. }
  74. //1. 打开开屏广告
  75. -(void)openSplashAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  76. [self.splashview opensplashAd:adName callback:callback];
  77. }
  78. //2.打开全屏广告
  79. -(void)openFullScreenVideoAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  80. [self.fullscreenVideo openFullScreenVideoAd:adName callback:callback];
  81. }
  82. //3.2打开新插屏广告
  83. -(void)openNewInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
  84. [self.interstitialNewAd openNewInterstitialAd:adName callback:callback];
  85. }
  86. //3.打开插屏广告
  87. -(void)openExpressInterstitialAd:(NSString *)adName Width:(CGFloat)w Height:(CGFloat)h callback:(void (^)(BOOL))callback{
  88. [self.interstitialAd openInterstitialAd:adName Width:w Height:h callback:callback];
  89. }
  90. //4. 打开视频激励广告
  91. -(void)openExpressRewardedVideoAd:(NSString *)adName callback:(void (^)(BOOL,BOOL))callback{
  92. [self.rewardedVideo openRewardedVideoAd:adName callback:callback];
  93. }
  94. //5.打开横幅广告
  95. -(void)openNativeExpressBannerAd:(NSString *)adName WithX:(CGFloat)x Y:(CGFloat)y Width:(CGFloat)w Height:(CGFloat)h callback:(void (^)(BOOL))callback {
  96. [self.nativeBanner openNativeExpressBannerAd:adName WithX:x Y:y Width:w Height:h callback:callback];
  97. }
  98. //5.2 关闭横幅广告
  99. -(void)closeBannerAd:(NSString *)adName {
  100. [self.nativeBanner closeBanner:adName];
  101. }
  102. //6. 打开原生广告
  103. -(void)openNativeAd:(NSString *)adName WidthCGRect:(CGRect)rect BUSize:(NSInteger)size callback:(void (^)(BOOL))callback {
  104. [self.nativeAd openNativeAd:adName WidthCGRect:rect BUSize:size callback:callback];
  105. }
  106. @end