123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //
- // 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)openNativeAdTop:(int)top left:(int)left bottom:(int)bottom right:(int)right{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.nativeContainer.hidden = false;
- CGSize size = [UIScreen mainScreen].bounds.size;
- CGRect rect;
-
- //默认:left=40,right=40, bottom=40,top=40
- if ([GMTools isIPhoneXSeries]){
- //rect = CGRectMake(40,size.height- 114-(size.width - 80)/5.0*3.5, size.width - 80, (size.width - 80)/5.0*3.5);
- rect = CGRectMake(left,size.height- 114-(size.width-top-bottom)/5.0*3.5, size.width - (left + right), (size.width - top-bottom)/5.0*3.5);
- }else{
- //rect = CGRectMake(40, size.height-90-(size.width -80)/5.0*2, size.width - 80, (size.width -80)/5.0*2);
- rect = CGRectMake(left, size.height-90-(size.width -top-bottom)/5.0*2, size.width - (left+right), (size.width - top-bottom)/5.0*2);
- }
-
- self.nativeContainer.frame = rect;
-
- });
- [self.admobNativeAd openWithSuperView:self.nativeContainer];
-
-
- }
- /// 关闭Banner广告
- -(void)closeAd:(NSString *)adName{
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([adName isEqualToString:@"banner"]) {
- for (UIView *vi in self.bannerContainer.subviews) {
- [vi removeFromSuperview];
- }
- self.bannerContainer.hidden = true;
- [self.admobBannerAd loadAd];
- }
-
- if ([adName isEqualToString:@"nativeAd"]) {
- 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];
- [ISIntegrationHelper validateIntegration];
-
- 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
|