123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // GMAdManager.m
- // Moriss
- //
- // Created by Mgs on 2020/8/22.
- //
- #import "GMAdManager.h"
- #import "GMTools.h"
- @interface GMAdManager()
- @property(nonatomic,strong)UIView *bannerContainer;
- @property(nonatomic,strong)UIView *nativeContainer;
- @end
- @implementation GMAdManager
- /// 打开Banner广告
- -(void)openAd:(NSString *)adName{
- //以"banner_"开头
- if ([adName hasPrefix:@"banner_"]) {
- self.bannerContainer.hidden = false;
-
- //横幅广告(Google Mob)
- if (self.admobBannerAd.isReady) {
- [self.admobBannerAd openWithSuperView:self.bannerContainer];
- }else{
- //横幅广告(横ironSource)
- [self.admobNativeAd loadAd];
- [self.isBannerAd openWithSuperView:self.bannerContainer];
- }
- }
-
-
-
- // if ([@"nativeAd" isEqualToString:adName]) {
- // [self openNativeAdTop:0 left:0 bottom:0 right:0];
- // }
- }
- /// 打开Banner广告(ironSource平台)
- -(void)openIronSourceAd:(NSString *)adName {
-
- }
- //打开原生广告
- -(void)openNativeAdWithX:(int)x Y:(int)y width:(int)w height:(int)h{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.nativeContainer.hidden = false;
- //CGSize size = [UIScreen mainScreen].bounds.size;
- CGRect rect;
- //rect = CGRectMake(40, size.height-90-(size.width -80)/5.0*2, size.width - 80, (size.width -80)/5.0*2);
- if ([GMTools isIPhoneXSeries]){
- rect = CGRectMake(x, y+44, w, h);
- }else{
- rect = CGRectMake(x, y, w, h);
- }
-
- self.nativeContainer.frame = rect;
- [self.admobNativeAd openWithSuperView:self.nativeContainer];
- });
- }
- /// 关闭Banner广告
- -(void)closeAd:(NSString *)adName{
- dispatch_async(dispatch_get_main_queue(), ^{
-
- //1.横幅广告关闭
- if ([adName isEqualToString:@"banner"]) {
- for (UIView *vi in self.bannerContainer.subviews) {
- [vi removeFromSuperview];
- }
- self.bannerContainer.hidden = true;
- [self.admobBannerAd loadAd];
- }
-
- //2.原生广告关闭
- if ([adName isEqualToString:@"native"]) {
- for (UIView *vi in self.nativeContainer.subviews) {
- [vi removeFromSuperview];
- }
- self.nativeContainer.hidden = true;
- [self.admobNativeAd loadAd];
- }
- });
- }
- /// 打开视频广告1
- -(void)openVideoAd:(NSString *)adName callback:(void (^)(BOOL))callback{
- [self.rewardVideoAd openVideo:adName callback:callback];
- }
- /// 打开积分墙广告
- -(void)openofferWallAd:(NSString *)adName callback:(void (^)(BOOL))callback {
- [self.offerWallVideoAd openOfferWallVideo:adName callback:callback];
- }
- /// 打开插页广告
- -(void)openinterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
- [self.interstitialAd openInterstitial:adName callback:callback];
- }
- #pragma mark - 单利 懒加载
- + (instancetype)sharedInstance{return [[super alloc]init];}
- + (instancetype)allocWithZone:(struct _NSZone *)zone {
- static GMAdManager *instance;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- instance = [super allocWithZone:zone];
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- NSString *APP_KEY = [infos objectForKey:@"ironsource-app-key"];
- NSString *userId = [infos objectForKey:@"ironsource-app-userId"];
- //NSLog(@"userId=%@",userId);
- NSLog(@"APP_KEY=%@",APP_KEY);
-
- [IronSource setUserId:userId];
- [IronSource initWithAppKey:APP_KEY];
-
- #ifdef DEBUG
- // Debug模式的代码...
- [ISIntegrationHelper validateIntegration]; //验证集成结果,根据打印日志判断, 生产环境的的sdk记得注释掉!!!
- #else
- // Release模式的代码...
- #endif
-
- instance.isBannerAd = [[FqIronsourceBanner alloc]init]; //ironsourceBanner
- instance.rewardVideoAd = [[FqIronsourceVideo alloc]init];
- instance.offerWallVideoAd = [[FqIronsourceOfferWall alloc]init];
- instance.admobBannerAd = [[FqAdmobNativeBanner alloc]init];
- [instance.admobBannerAd loadAd];
- instance.admobNativeAd = [[FqAdmobNativeAd alloc]init];
- [instance.admobNativeAd loadAd];
-
- //
- instance.interstitialAd = [[FqIronsourceInterstitial alloc]init];
-
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- instance.bannerContainer = [[UIView alloc]init];
- instance.bannerContainer.backgroundColor = [UIColor clearColor];
- UIViewController *vc = [GMTools getViewControl];
- [vc.view addSubview:instance.bannerContainer];
- CGSize size = [UIScreen mainScreen].bounds.size;
- float height = 60;
- if ([GMTools isIPhoneXSeries]) height += 30;
- instance.bannerContainer.frame = CGRectMake(0, size.height-height, size.width, height);
- instance.bannerContainer.hidden = true;
- });
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- instance.nativeContainer = [[UIView alloc]init];
- instance.nativeContainer.backgroundColor = [UIColor clearColor];
- UIViewController *vc = [GMTools getViewControl];
- [vc.view addSubview:instance.nativeContainer];
- instance.nativeContainer.hidden = true;
- });
-
- });
- return instance;
- }
- @end
|