FqGameAd.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // FqGameAd.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2020/12/25.
  6. // Copyright © 2020 SAGESSE. All rights reserved.
  7. //
  8. #import "FqGameAd.h"
  9. #import "XZTool.h"
  10. @interface FqGameAd()
  11. //1.横幅广告
  12. //@property (nonatomic, strong)AdBanner *defBanner;
  13. ////
  14. //////2.插页广告
  15. @property (nonatomic, strong)AdInner *defInner;
  16. ////
  17. //////3.激励视频广告
  18. @property (nonatomic, strong)AdRewarded *defRewarded;
  19. //
  20. ////4.OfferWall广告
  21. //@property (nonatomic, strong)AdOfferWall *defOfferWall;
  22. //
  23. ////5.原生广告
  24. @property (nonatomic, strong)AdNative *defNative;
  25. @end
  26. @implementation FqGameAd
  27. +(instancetype)fqGameAD {
  28. static id fqGameAD = nil;
  29. static dispatch_once_t onceToken;
  30. dispatch_once(&onceToken, ^{
  31. fqGameAD = [[FqGameAd alloc]init];
  32. });
  33. return fqGameAD;
  34. }
  35. - (instancetype)init
  36. {
  37. self = [super init];
  38. if (self) {
  39. //init
  40. // self.defBanner = [[ISAdBanner alloc]init];
  41. self.defInner = [[ISAdInner alloc]init];
  42. self.defRewarded = [[ISAdRewarded alloc]init];
  43. // self.defOfferWall = [[ISAdOfferWall alloc]init];
  44. self.defNative = [[AdmobNative alloc]init];
  45. //配置
  46. [ISSupersonicAdsConfiguration configurations].useClientSideCallbacks = @(YES);
  47. NSBundle *mainBundle = [NSBundle mainBundle];
  48. NSString *userId = mainBundle.infoDictionary[@"ironsource-app-userId"];
  49. NSString *APP_KEY = mainBundle.infoDictionary[@"ironsource-app-key"];
  50. NSLog(@"userId=%@",userId);
  51. NSLog(@"APP_KEY=%@",APP_KEY);
  52. [IronSource setUserId:userId];
  53. [IronSource initWithAppKey:APP_KEY];
  54. [ISIntegrationHelper validateIntegration];
  55. [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
  56. [GADMobileAds sharedInstance].requestConfiguration.testDeviceIdentifiers = @[@"d2f3edea5fa209e7aafe5a1f92053835"];
  57. }
  58. return self;
  59. }
  60. ///通过adId打开广告.
  61. -(void)openAd:(NSString *)adName {
  62. id obj = [[XZTool share].dict objectForKey:adName];
  63. if (obj) {
  64. if ([obj isKindOfClass:[ISAdBanner class]]) {
  65. ISAdBanner *inner = [[XZTool share].dict objectForKey:adName];
  66. [inner play:adName callback:^(int intValue) {
  67. }];
  68. }
  69. if ([obj isKindOfClass:[ISAdInner class]]) {
  70. ISAdInner *inner = [[XZTool share].dict objectForKey:adName];
  71. [inner play:adName callback:^(int intValue) {
  72. }];
  73. }
  74. if ([obj isKindOfClass:[AdRewarded class]]) {
  75. AdRewarded *inner = [[XZTool share].dict objectForKey:adName];
  76. [inner play:adName callback:^(int intValue) {
  77. }];
  78. }
  79. if ([obj isKindOfClass:[AdmobNative class]]) {
  80. AdmobNative *inner = [[XZTool share].dict objectForKey:adName];
  81. [inner play:adName callback:^(int intValue) {
  82. }];
  83. }
  84. }
  85. if (obj == nil) {
  86. NSLog(@"没有准备好的广告~~~");
  87. }
  88. }
  89. ///查询广告是否准备好
  90. -(BOOL)isAdReady:(NSString *)adName {
  91. id obj = [[XZTool share].dict objectForKey:adName];
  92. if (obj) {
  93. if ([obj isKindOfClass:[ISAdBanner class]]) {
  94. ISAdBanner *inner = [[XZTool share].dict objectForKey:adName];
  95. return [inner isReady];
  96. }
  97. if ([obj isKindOfClass:[ISAdInner class]]) {
  98. ISAdInner *inner = [[XZTool share].dict objectForKey:adName];
  99. return [inner isReady];
  100. }
  101. if ([obj isKindOfClass:[AdRewarded class]]) {
  102. AdRewarded *inner = [[XZTool share].dict objectForKey:adName];
  103. return [inner isReady];
  104. }
  105. // if ([obj isKindOfClass:[AdOfferWall class]]) {
  106. // AdOfferWall *inner = [[XZTool share].dict objectForKey:adName];
  107. // return [inner isReady];
  108. // }
  109. if ([obj isKindOfClass:[AdmobNative class]]) {
  110. AdmobNative *inner = [[XZTool share].dict objectForKey:adName];
  111. return [inner isReady];
  112. }
  113. }
  114. return NO;
  115. }
  116. ///
  117. -(AdBanner*)getBanner:(NSString *)adId {
  118. id obj = [[XZTool share].dict objectForKey:adId];
  119. if ([obj isKindOfClass:[AdBanner class]]) {
  120. AdBanner *banner = [[XZTool share].dict objectForKey:adId];
  121. if (banner) {
  122. return banner;
  123. }
  124. }
  125. //没有缓存,新创建.
  126. AdBanner *banner = [[ISAdBanner alloc]init];
  127. banner.adId = adId;
  128. [[XZTool share].dict setValue:banner forKey:adId];
  129. return banner;
  130. }
  131. -(AdInner *)getInner {
  132. return self.defInner;
  133. }
  134. -(AdRewarded *)getRewarded {
  135. return self.defRewarded;
  136. }
  137. //
  138. //-(AdOfferWall *)getOfferWall {
  139. // return self.defOfferWall;
  140. //}
  141. //
  142. -(AdNative *)getNative {
  143. return self.defNative;
  144. }
  145. ///关闭横幅广告
  146. -(void)closeBanner:(NSString *)adId {
  147. AdBanner *banner = [self getBanner:adId];
  148. if (banner != nil) {
  149. [banner close];
  150. }
  151. }
  152. ///显示横幅广告
  153. -(void)showBanner:(NSString *)adId {
  154. //AdBanner *banner = [self getBanner:adId];
  155. //每次都创建新的广告.
  156. AdBanner *banner = [[ISAdBanner alloc]init];
  157. banner.adId = adId;
  158. [[XZTool share].dict setValue:banner forKey:adId];
  159. [banner play:adId callback:^(int intValue) {
  160. }];
  161. }
  162. //显示插页广告
  163. - (void)showInner:(NSString*)adId callback:(void(^)(int intValue))back {
  164. //AdInner *banner = [self getInner:adId];
  165. self.defInner.adId = adId;
  166. if (self.defInner) {
  167. [self.defInner play:adId callback:^(int intValue) {
  168. back(intValue);
  169. }];
  170. }else{
  171. back(-1);
  172. }
  173. }
  174. //显示激励视频广告
  175. - (void)showVideo:(NSString*)adId callback:(void(^)(int intValue))back {
  176. //AdRewarded *banner = [self getRewarded:adId];
  177. self.defRewarded.adId = adId;
  178. if (self.defRewarded) {
  179. [self.defRewarded play:adId callback:^(int intValue) {
  180. back(intValue);
  181. }];
  182. }else{
  183. back(-1);
  184. }
  185. }
  186. //显示原生广告
  187. -(void)showAdNative:(NSString *)adId x:(int)x y:(int)y w:(int)w h:(int)h {
  188. //AdNative *inner = [self getNative:adId];
  189. self.defNative.adId = adId;
  190. if (self.defNative) {
  191. [self.defNative showNativeWithID:adId X:x Y:y W:w H:h];
  192. }
  193. }
  194. //关闭原生广告
  195. -(void)closeNative {
  196. AdNative *banner = [self getNative];
  197. if (banner != nil) {
  198. [banner close];
  199. }
  200. }
  201. //关闭原生广告--by广告位名称
  202. -(void)closeNative:(NSString *)adId {
  203. id obj = [[XZTool share].dict objectForKey:adId];
  204. if ([obj isKindOfClass:[AdNative class]]) {
  205. AdNative *banner = [[XZTool share].dict objectForKey:adId];
  206. [banner close];
  207. }
  208. }
  209. ///刷新原生广告
  210. -(void)refreshNative{
  211. AdNative *banner = [self getNative];
  212. if (banner) {
  213. [banner refreshAd];
  214. }
  215. }
  216. @end