// // 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