123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- //
- // FqGameAd.m
- // XenonSDK
- //
- // Created by fq on 2020/12/25.
- // Copyright © 2020 SAGESSE. All rights reserved.
- //
- #import "FqGameAd.h"
- #import "XZTool.h"
- @interface FqGameAd()
- //1.横幅广告
- //@property (nonatomic, strong)AdBanner *defBanner;
- ////
- //////2.插页广告
- @property (nonatomic, strong)AdInner *defInner;
- ////
- //////3.激励视频广告
- @property (nonatomic, strong)AdRewarded *defRewarded;
- //
- ////4.OfferWall广告
- //@property (nonatomic, strong)AdOfferWall *defOfferWall;
- //
- ////5.原生广告
- @property (nonatomic, strong)AdNative *defNative;
- @end
- @implementation FqGameAd
- +(instancetype)fqGameAD {
- static id fqGameAD = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- fqGameAD = [[FqGameAd alloc]init];
- });
- return fqGameAD;
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
-
- //init
- // self.defBanner = [[ISAdBanner alloc]init];
- self.defInner = [[ISAdInner alloc]init];
- self.defRewarded = [[ISAdRewarded alloc]init];
-
- // self.defOfferWall = [[ISAdOfferWall alloc]init];
- self.defNative = [[AdmobNative alloc]init];
-
- //配置
- [ISSupersonicAdsConfiguration configurations].useClientSideCallbacks = @(YES);
-
-
- NSBundle *mainBundle = [NSBundle mainBundle];
- NSString *userId = mainBundle.infoDictionary[@"ironsource-app-userId"];
- NSString *APP_KEY = mainBundle.infoDictionary[@"ironsource-app-key"];
- NSLog(@"userId=%@",userId);
- NSLog(@"APP_KEY=%@",APP_KEY);
-
- [IronSource setUserId:userId];
- [IronSource initWithAppKey:APP_KEY];
-
-
- [ISIntegrationHelper validateIntegration];
- [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
- [GADMobileAds sharedInstance].requestConfiguration.testDeviceIdentifiers = @[@"d2f3edea5fa209e7aafe5a1f92053835"];
- }
- return self;
- }
- ///通过adId打开广告.
- -(void)openAd:(NSString *)adName {
- id obj = [[XZTool share].dict objectForKey:adName];
-
- if (obj) {
-
- if ([obj isKindOfClass:[ISAdBanner class]]) {
- ISAdBanner *inner = [[XZTool share].dict objectForKey:adName];
- [inner play:adName callback:^(int intValue) {
- }];
- }
-
- if ([obj isKindOfClass:[ISAdInner class]]) {
- ISAdInner *inner = [[XZTool share].dict objectForKey:adName];
- [inner play:adName callback:^(int intValue) {
-
- }];
- }
-
- if ([obj isKindOfClass:[AdRewarded class]]) {
- AdRewarded *inner = [[XZTool share].dict objectForKey:adName];
- [inner play:adName callback:^(int intValue) {
-
- }];
- }
- if ([obj isKindOfClass:[AdmobNative class]]) {
- AdmobNative *inner = [[XZTool share].dict objectForKey:adName];
- [inner play:adName callback:^(int intValue) {
-
- }];
- }
- }
-
- if (obj == nil) {
- NSLog(@"没有准备好的广告~~~");
- }
-
- }
- ///查询广告是否准备好
- -(BOOL)isAdReady:(NSString *)adName {
- id obj = [[XZTool share].dict objectForKey:adName];
-
- if (obj) {
-
-
- if ([obj isKindOfClass:[ISAdBanner class]]) {
- ISAdBanner *inner = [[XZTool share].dict objectForKey:adName];
- return [inner isReady];
- }
-
- if ([obj isKindOfClass:[ISAdInner class]]) {
- ISAdInner *inner = [[XZTool share].dict objectForKey:adName];
- return [inner isReady];
- }
-
- if ([obj isKindOfClass:[AdRewarded class]]) {
- AdRewarded *inner = [[XZTool share].dict objectForKey:adName];
- return [inner isReady];
- }
-
- // if ([obj isKindOfClass:[AdOfferWall class]]) {
- // AdOfferWall *inner = [[XZTool share].dict objectForKey:adName];
- // return [inner isReady];
- // }
-
- if ([obj isKindOfClass:[AdmobNative class]]) {
- AdmobNative *inner = [[XZTool share].dict objectForKey:adName];
- return [inner isReady];
- }
- }
- return NO;
- }
-
- ///
- -(AdBanner*)getBanner:(NSString *)adId {
- id obj = [[XZTool share].dict objectForKey:adId];
-
- if ([obj isKindOfClass:[AdBanner class]]) {
- AdBanner *banner = [[XZTool share].dict objectForKey:adId];
- if (banner) {
- return banner;
- }
- }
-
- //没有缓存,新创建.
- AdBanner *banner = [[ISAdBanner alloc]init];
- banner.adId = adId;
- [[XZTool share].dict setValue:banner forKey:adId];
- return banner;
- }
- -(AdInner *)getInner {
- return self.defInner;
- }
- -(AdRewarded *)getRewarded {
- return self.defRewarded;
- }
- //
- //-(AdOfferWall *)getOfferWall {
- // return self.defOfferWall;
- //}
- //
- -(AdNative *)getNative {
- return self.defNative;
- }
- ///关闭横幅广告
- -(void)closeBanner:(NSString *)adId {
- AdBanner *banner = [self getBanner:adId];
- if (banner != nil) {
- [banner close];
- }
- }
- ///显示横幅广告
- -(void)showBanner:(NSString *)adId {
- //AdBanner *banner = [self getBanner:adId];
-
- //每次都创建新的广告.
- AdBanner *banner = [[ISAdBanner alloc]init];
- banner.adId = adId;
- [[XZTool share].dict setValue:banner forKey:adId];
-
- [banner play:adId callback:^(int intValue) {
-
- }];
- }
- //显示插页广告
- - (void)showInner:(NSString*)adId callback:(void(^)(int intValue))back {
- //AdInner *banner = [self getInner:adId];
- self.defInner.adId = adId;
- if (self.defInner) {
- [self.defInner play:adId callback:^(int intValue) {
- back(intValue);
- }];
- }else{
- back(-1);
- }
- }
- //显示激励视频广告
- - (void)showVideo:(NSString*)adId callback:(void(^)(int intValue))back {
- //AdRewarded *banner = [self getRewarded:adId];
- self.defRewarded.adId = adId;
- if (self.defRewarded) {
- [self.defRewarded play:adId callback:^(int intValue) {
- back(intValue);
- }];
- }else{
-
- back(-1);
- }
- }
- //显示原生广告
- -(void)showAdNative:(NSString *)adId x:(int)x y:(int)y w:(int)w h:(int)h {
- //AdNative *inner = [self getNative:adId];
- self.defNative.adId = adId;
- if (self.defNative) {
- [self.defNative showNativeWithID:adId X:x Y:y W:w H:h];
- }
- }
- //关闭原生广告
- -(void)closeNative {
- AdNative *banner = [self getNative];
- if (banner != nil) {
- [banner close];
-
- }
- }
- //关闭原生广告--by广告位名称
- -(void)closeNative:(NSString *)adId {
- id obj = [[XZTool share].dict objectForKey:adId];
- if ([obj isKindOfClass:[AdNative class]]) {
- AdNative *banner = [[XZTool share].dict objectForKey:adId];
- [banner close];
- }
- }
- ///刷新原生广告
- -(void)refreshNative{
- AdNative *banner = [self getNative];
- if (banner) {
- [banner refreshAd];
- }
- }
- @end
|