// // RQADViewManager.m // jiaPei // // Created by 张嵘 on 2021/4/29. // Copyright © 2021 JCZ. All rights reserved. // #import "RQADViewManager.h" #import "YYTimer.h" // 支持广点通开屏广告v+ #define SUPPORT_SPLASH_ZOOMOUT 1 NSString * const RQADInterstitialNotificationName = @"RQADInterstitialNotificationName"; #if defined(__IPHONE_14_0) #import //适配iOS14 #endif static RQADViewManager *manger = nil; static dispatch_once_t onceToken; static NSString *splashPlcId = @"cca7ca16b609a5f82f"; static NSString *bannerPlcId = @"0702543ed7029244f5"; static NSString *bannerPlcId2 = @"389c6b76a6fb66ea00"; static NSString *homePageBannerPlcId = @"51fe9c4b24041952f6"; static NSString *nativeAdPlcId = @"41c0bc7485d4afc80b"; static NSString *intertitialAdPlcId = @"ee0c6fafec9f36389a"; //插屏开屏广告 static NSString *intertitialSplashAdPlcId = @"4077434dc98ce267ed"; @interface RQADViewManager () /* 插屏广告 */ //@property (nonatomic,strong) ADCDN_InterstitialAdManager *interstitialAdManager; /* 开屏广告对象 */ @property (nonatomic, readwrite, strong) ADSuyiSDKSplashAd *splashAd; /* 横幅广告 */ @property (nonatomic, readwrite, strong) ADSuyiSDKBannerAdView *bannerView; /* 信息流广告 */ @property (nonatomic, readwrite, strong) ADSuyiSDKNativeAd *nativeAd; /* 插屏广告 */ @property (nonatomic, readwrite, strong) ADSuyiSDKIntertitialAd *intertitialAd; @property (nonatomic, readwrite, strong) UIView *currentAdView; @property (nonatomic, readwrite, strong) UIView *customView; @property (nonatomic, readwrite, strong) UIViewController *customViewController; @property (nonatomic, readwrite, assign) BOOL isResume; @property (nonatomic, readwrite, copy) RQADCloseCompletedBlock aDCloseCompletedBlock; @property (nonatomic, readwrite, strong) UIButton *skipBtn; @property (nonatomic, readwrite, strong) YYTimer *timer; @property (nonatomic, readwrite, assign) NSUInteger count; @property (nonatomic, readwrite, assign) BOOL isReady; @property (nonatomic, readwrite, assign) BOOL isCanShow; @property (nonatomic, readwrite, copy) NSString *appId; @end @implementation RQADViewManager #pragma mark - SystemMethod + (RQADViewManager *)sharedManager { dispatch_once(&onceToken, ^{ manger = [[self alloc] init]; }); return manger; } - (instancetype)init { self = [super init]; if (self) { [self initBaseData]; } return self; } - (void)dealloc { } #pragma mark - PublicMethods // 配置广告SDK - (void)rq_configureADSuiSDK { if ([RQ_AD_MANAGER isFirstAppLoad]) { [RQ_AD_MANAGER requestAgreePrivacy]; } else { [RQ_AD_MANAGER initADSuyiSDK]; } [NY_AD_MANAGER ny_configureADSuiSDK]; } - (void)loadMineSplashAd { NSInteger randomAdNum = arc4random() % 100; RQADType splashAdType = (randomAdNum <= RQ_SHARE_FUNCTION.APP_KP)? RQADType_Splash : ([RQ_AD_MANAGER isFirstAppLoad]? RQADType_Splash : RQADType_InterstitialSplash); // if (splashAdType == RQADType_InterstitialSplash) { // RQ_APPDELEGATE.splashWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // RQ_APPDELEGATE.splashWindow.backgroundColor = [UIColor whiteColor]; // UIViewController * vc = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateInitialViewController]; // [RQ_APPDELEGATE.splashWindow setRootViewController:vc]; // [RQ_APPDELEGATE.splashWindow makeKeyAndVisible]; // } // if (myDelegate.isLogin) { // [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) { // }]; // if (RQ_COMMON_MANAGER.isHideSplashAD) { // ///会员,如果展示开屏需要把splashWindow隐藏 // if (splashAdType == RQADType_InterstitialSplash) [self resetWindow]; // } else { // [RQ_AD_MANAGER loadAdWithAdType:splashAdType customView:nil];/// 非会员,初始化广告SDK并展示开屏广告 // } // } else { // [RQ_AD_MANAGER loadAdWithAdType:splashAdType customView:nil]; /// 无登录,初始化广告SDK并展示开屏广告 // } [RQ_AD_MANAGER loadAdWithAdType:splashAdType customView:nil]; } - (void)loadAdWithAdType:(RQADType)adType customView:(UIView * _Nullable )customView { NSLog(@"VC==%@",customView); [self loadAdWithAdType:adType customView:customView cycleSecound:0.f]; } - (void)loadAdWithAdType:(RQADType)adType customView:(UIView * _Nullable )customView cycleSecound:(CGFloat)second { [self loadAdWithAdType:adType customView:customView controller:RQControllerHelper.currentViewController cycleSecound:second]; } - (void)loadAdWithAdType:(RQADType)adType customView:(UIView * _Nullable )customView controller:(UIViewController *)controller cycleSecound:(CGFloat)second { NSLog(@"===============VCC=%@",controller); @weakify(self) self.isNativeAdClicked = NO; self.adType = adType; self.customView = customView; self.customViewController = controller; if (adType == RQADType_Banner_IN) { self.bannerView.delegate = nil; self.bannerView = nil; [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } if (second > 0) { RACSignal *deallocSignal = [self.customViewController rac_signalForSelector:@selector(viewDidDisappear:)]; [[[RACSignal interval:second onScheduler:[RACScheduler mainThreadScheduler]] takeUntil: deallocSignal] subscribeNext:^(NSDate * _Nullable x) { @strongify(self) if (self.customView.hidden) { [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } } }]; } } else { /// 服务端允许展示广告 if (RQ_COMMON_MANAGER.JSJP_APP_AD_OPEN) { if (RQ_VIP_Module.isVip) { switch (adType) { case RQADType_Splash: { [self loadSplashAd]; break; } case RQADType_InterstitialSplash: { /// 非两个广告以上 if (!RQ_VIP_Module.isADVip) { int a = arc4random() % 100; NSLog(@"RATE=%zd AD=%d",RQ_COMMON_MANAGER.JSJP_APP_AD_RATE,a); int date = [RQ_USER_MANAGER.city_dbId isEqualToString:@"3502"]?RQ_COMMON_MANAGER.JSJP_APP_XM_AD_RATE:RQ_COMMON_MANAGER.JSJP_APP_AD_RATE; if (date > a) { self.isReady = NO; _intertitialAd = nil; NSLog(@"AD===VC=%@",self.intertitialAd.controller); [self.intertitialAd loadAdData]; } } break; } case RQADType_Banner: { if (RQ_VIP_Module.isSubject1Vip && RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) { } else if (RQ_VIP_Module.isSubject4Vip && RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) { } else { self.bannerView.delegate = nil; self.bannerView = nil; [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } if (second > 0) { RACSignal *deallocSignal = [self.customViewController rac_signalForSelector:@selector(viewDidDisappear:)]; [[[RACSignal interval:second onScheduler:[RACScheduler mainThreadScheduler]] takeUntil: deallocSignal] subscribeNext:^(NSDate * _Nullable x) { @strongify(self) if (self.customView.hidden) { [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } } }]; } } break; } default: break; } } else { switch (adType) { case RQADType_Splash: { [self loadSplashAd]; break; } case RQADType_InterstitialSplash: { int a = arc4random() % 100; NSLog(@"RATE=%zd AD=%d",RQ_COMMON_MANAGER.JSJP_APP_AD_RATE,a); int date = [RQ_USER_MANAGER.city_dbId isEqualToString:@"3502"]?RQ_COMMON_MANAGER.JSJP_APP_XM_AD_RATE:RQ_COMMON_MANAGER.JSJP_APP_AD_RATE; if (date > a) { self.isReady = NO; _intertitialAd = nil; NSLog(@"AD===VC=%@",self.intertitialAd.controller); [self.intertitialAd loadAdData]; } break; } case RQADType_Banner: { self.bannerView.delegate = nil; self.bannerView = nil; [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } if (second > 0) { RACSignal *deallocSignal = [self.customViewController rac_signalForSelector:@selector(viewDidDisappear:)]; [[[RACSignal interval:second onScheduler:[RACScheduler mainThreadScheduler]] takeUntil: deallocSignal] subscribeNext:^(NSDate * _Nullable x) { @strongify(self) if (self.customView.hidden) { [self.customView addSubview:self.bannerView]; if(_splashAd==nil){ [self.bannerView loadAndShow:self.customViewController]; } } }]; } break; } case RQADType_native: { [self.nativeAd load:1]; } break; case RQADType_fullScreen: { self.isReady = NO; _intertitialAd = nil; NSLog(@"AD===VC=%@",self.intertitialAd.controller); [_intertitialAd loadAdData]; } break; default: break; } } } } } - (void)showAdWithAdType:(RQADType)adType { if (RQ_COMMON_MANAGER.JSJP_APP_AD_OPEN) { switch (adType) { case RQADType_fullScreen: { if (self.isReady) { self.isCanShow = YES; [self.intertitialAd show]; } } break; default: break; } } } - (void)initCloseBlock:(RQADCloseCompletedBlock)block { self.aDCloseCompletedBlock = block; } - (BOOL)isFirstAppLoad { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; if ([[userDefault objectForKey:@"isFirstLoad"] isEqualToString:@"yes"]) { return NO; } return YES; } #pragma mark - PrivateMethods - (void)initBaseData { [[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil] map:^id(NSNotification *value) { return value.object; }] distinctUntilChanged] subscribeNext:^(id x) { NSLog(@"%@",@"APP进入后台"); }]; } - (void)requestAgreePrivacy { UIApplication *applicaiton = [UIApplication sharedApplication]; if (applicaiton.applicationState == UIApplicationStateActive) { if (@available(iOS 14, *)) { ATTrackingManagerAuthorizationStatus status = [ATTrackingManager trackingAuthorizationStatus]; if(status == ATTrackingManagerAuthorizationStatusNotDetermined|| status == ATTrackingManagerAuthorizationStatusDenied) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { // Tracking authorization completed. Start loading ads here. [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self writeAppLoad]; [self initADSuyiSDK]; [NY_AD_MANAGER requestAgreePrivacy]; }]; }]; } else { [self writeAppLoad]; [self initADSuyiSDK]; [NY_AD_MANAGER requestAgreePrivacy]; } } else { [self writeAppLoad]; [self initADSuyiSDK]; [NY_AD_MANAGER requestAgreePrivacy]; } } else { [self performSelector:@selector(requestAgreePrivacy) withObject:nil afterDelay:0.5f]; } } - (void)writeAppLoad { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:@"yes" forKey:@"isFirstLoad"]; [userDefault synchronize]; } - (void)initADSuyiSDK { // 设置日志输出等级 [ADSuyiSDK setLogLevel:ADSuyiKitLogLevelDebug]; // [ADSuyiSDK setOnlyPlatform:@"gdt"]; // ADSuyiSDK初始化 [ADSuyiSDK initWithAppId:self.appId completionBlock:^(NSError * _Nonnull error) { if (error) { NSLog(@"SDK 初始化失败:%@", error.localizedDescription); } }]; } //- (void)resetWindow { // RQ_APPDELEGATE.splashWindow.hidden = YES; // [RQ_APPDELEGATE.splashWindow resignKeyWindow]; // RQ_APPDELEGATE.splashWindow = nil; // [RQ_APPDELEGATE.window makeKeyAndVisible]; //} - (void)_timerValueChanged:(YYTimer *)timer { self.count--; if (self.count == 0) { [timer invalidate]; self.timer = nil; [self.skipBtn setTitleNormal:@"跳过"]; if (self.currentAdView) { [self.currentAdView adsy_close]; } return; } [self.skipBtn setTitleNormal:[NSString stringWithFormat:@"跳过 %zd", self.count]]; } - (void)loadSplashAd { if (self.splashAd) { return; } self.splashAd = [[ADSuyiSDKSplashAd alloc]init]; self.splashAd.delegate = self; self.splashAd.controller = RQControllerHelper.currentViewController; self.splashAd.posId = splashPlcId; self.splashAd.tolerateTimeout = 4; UIViewController * vc = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateInitialViewController]; CGRect rect = [UIScreen mainScreen].bounds; UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); vc.view.frame = rect; [vc.view.layer renderInContext:context]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.splashAd.backgroundColor = [UIColor adsy_getColorWithImage:image withNewSize:[UIScreen mainScreen].bounds.size]; [self.splashAd loadAndShowInWindow:RQ_APPDELEGATE.window]; } //获取当前屏幕显示的viewcontroller - (UIViewController *)getCurrentVC { UIViewController *resultVC; resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]]; /// RQ Fixed : 这里必须要判断一下,否则取出来永远都是 RQMainTabBarViewController。这是架构上小缺(特)陷(性)。因为RQMainTabBarViewController的子控制器是UITabBarController,所以需要递归UITabBarController的所有的子控制器 if ([resultVC isKindOfClass:[RQTableViewController class]]) { RQTableViewController *mainVc = (RQTableViewController *)resultVC; resultVC = [self _topViewController:mainVc.tabBarController]; } return resultVC; } - (UIViewController *)_topViewController:(UIViewController *)vc { if ([vc isKindOfClass:[UINavigationController class]]) { return [self _topViewController:[(UINavigationController *)vc topViewController]]; } else if ([vc isKindOfClass:[UITabBarController class]]) { return [self _topViewController:[(UITabBarController *)vc selectedViewController]]; } else { return vc; } } #pragma mark - ADSuyiSDKSplashAdDelegate /** 开屏展现成功 @param splashAd 广告实例 */ - (void)adsy_splashAdSuccessToPresentScreen:(ADSuyiSDKSplashAd *)splashAd{ // [self resetWindow]; } /** 开屏展现失败 @param splashAd 广告实例 @param error 具体错误信息 */ - (void)adsy_splashAdFailToPresentScreen:(ADSuyiSDKSplashAd *)splashAd failToPresentScreen:(ADSuyiAdapterErrorDefine *)error{ _splashAd = nil; // [self resetWindow]; } /** 开屏广告点击 @param splashAd 广告实例 */ - (void)adsy_splashAdClicked:(ADSuyiSDKSplashAd *)splashAd{ } /** 开屏被关闭 @param splashAd 广告实例 */ - (void)adsy_splashAdClosed:(ADSuyiSDKSplashAd *)splashAd{ _splashAd = nil; if (self.isReady && _intertitialAd) { UIViewController *vc = RQControllerHelper.currentViewController; _intertitialAd.controller = vc.tabBarController; [_intertitialAd show]; } if (_bannerView.superview) { [_bannerView loadAndShow:self.customViewController]; } // [RQNotificationCenter postNotificationName:RQADInterstitialNotificationName object:nil]; } /** 开屏展示 @param splashAd 广告实例 */ - (void)adsy_splashAdEffective:(ADSuyiSDKSplashAd *)splashAd{ } #pragma mark - ADSuyiSDKBannerAdViewDelegate /** 广告获取成功 @param bannerView banner实例 */ - (void)adsy_bannerViewDidReceived:(ADSuyiSDKBannerAdView *)bannerView { NSLog(@"bannerView--获取成功"); // if (self.adType == RQADType_Banner_IN) { // bannerView.qmui_width = RQ_SCREEN_WIDTH - 32.f; // } self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Success) : nil; } /** 广告拉取失败 @param bannerView banner实例 @param errorModel 错误描述 */ - (void)adsy_bannerViewFailToReceived:(ADSuyiSDKBannerAdView *)bannerView errorModel:(ADSuyiAdapterErrorDefine *)errorModel{ NSLog(@"adsy_bannerViewFailToReceived:%@, %@",errorModel.errorDescription, errorModel.errorDetailDict); // [_bannerView removeFromSuperview]; // _bannerView = nil; self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Faild) : nil; } /** 广告点击 @param bannerView 广告实例 */ - (void)adsy_bannerViewClicked:(ADSuyiSDKBannerAdView *)bannerView{ } /** 广告关闭 @param bannerView 广告实例 */ - (void)adsy_bannerViewClose:(ADSuyiSDKBannerAdView *)bannerView{ // [_bannerView removeFromSuperview]; // _bannerView = nil; self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Close) : nil; } /** 广告展示 @param bannerView 广告实例 */ - (void)adsy_bannerViewExposure:(ADSuyiSDKBannerAdView *)bannerView{ } - (void)adsy_bannerAdCloseLandingPage:(nonnull ADSuyiSDKBannerAdView *)bannerView { } - (void)adsy_bannerViewDidPresent:(nonnull ADSuyiSDKBannerAdView *)bannerView { } #pragma mark - ADSuyiSDKNativeAdDelegate - (void)adsy_nativeAdSucessToLoad:(ADSuyiSDKNativeAd *)nativeAd adViewArray:(NSArray<__kindof UIView *> *)adViewArray { for (UIView *adView in adViewArray) { // 4、判断信息流广告是否为自渲染类型(可选实现) 可仿照所示样式demo实现 如无所需样式则需自行实现 // 如果单纯只配置了模版信息流,那么不需要实现,如果配置了自渲染信息流,那么需要实现 if(adView.renderType == ADSuyiAdapterRenderTypeNative) { // 4.1、如果是自渲染类型则可样式自定义(3种示例demo样式见下) // 1、常规样式 // [self setUpUnifiedTopImageNativeAdView:adView]; // 2、纯图样式 [self setUpUnifiedOnlyImageNativeAdView:adView]; // 3、上图下文 // [self setUpUnifiedTopImageNativeAdView:adView]; } // 5、注册,自渲染:注册点击事件,模板:render,重要 [adView adsy_registViews:@[adView]]; // 广点通视频信息流广告会给mediaView添加事件,点击会出现半屏广告,以下为广点通官方给予的解决方案 if([adView.adsy_platform isEqualToString:ADSuyiAdapterPlatformGDT] && adView.renderType == ADSuyiAdapterRenderTypeNative && adView.data.shouldShowMediaView) { UIView *mediaView = [adView adsy_mediaViewForWidth:0.0]; mediaView.userInteractionEnabled = NO; } } } - (void)adsy_nativeAdFailToLoad:(ADSuyiSDKNativeAd *)nativeAd errorModel:(ADSuyiAdapterErrorDefine *)errorModel { self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Faild) : nil; } - (void)adsy_nativeAdViewRenderOrRegistSuccess:(UIView *)adView { self.currentAdView = adView; for (UIView *subview in self.customView.subviews) { if ([subview.className isEqualToString:@"ADSuyiGDTUnifiedNativeAdView"]) { [subview removeFromSuperview]; } } [self.customView addSubview:self.currentAdView]; } - (void)adsy_nativeAdViewRenderOrRegistFail:(UIView *)adView { self.currentAdView = adView; self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Faild) : nil; } - (void)adsy_nativeAdClicked:(ADSuyiSDKNativeAd *)nativeAd adView:(__kindof UIView *)adView { self.isNativeAdClicked = YES; if(RQ_AD_MANAGER.adType==RQADType_fullScreen||RQ_AD_MANAGER.adType==RQADType_native){ return; } self.currentAdView = adView; [self.timer invalidate]; self.timer = nil; [adView adsy_close]; } - (void)adsy_nativeAdClose:(ADSuyiSDKNativeAd *)nativeAd adView:(__kindof UIView *)adView { if(!self.isNativeAdClicked) { if (self.currentAdView) { self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Close) : nil; self.currentAdView = adView; [self.currentAdView removeFromSuperview]; [self.skipBtn removeFromSuperview]; [UIView removeSubviewsRecursively:self.currentAdView]; self.currentAdView = nil; self.nativeAd = nil; } } } - (void)adsy_nativeAdExposure:(ADSuyiSDKNativeAd *)nativeAd adView:(__kindof UIView *)adView { self.currentAdView = adView; [self.customView bringSubviewToFront:self.skipBtn]; self.count = 5; [_skipBtn setTitleNormal:@"跳过 5"]; self.timer = [YYTimer timerWithTimeInterval:1 target:self selector:@selector(_timerValueChanged:) repeats:YES]; self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Success) : nil; } - (void)adsy_nativeAdCloseLandingPage:(ADSuyiSDKNativeAd *)nativeAd adView:(__kindof UIView *)adView{ if(self.isNativeAdClicked) { if (self.currentAdView) { self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Close) : nil; self.currentAdView = adView; [self.currentAdView removeFromSuperview]; [self.skipBtn removeFromSuperview]; [UIView removeSubviewsRecursively:self.currentAdView]; self.currentAdView = nil; self.nativeAd = nil; } NSLog(@"adsy_nativeAdCloseLandingPage"); } } - (void)adsy_nativeAd:(ADSuyiSDKNativeAd *)nativeAd adView:(nonnull __kindof UIView *)adView playerStatusChanged:(ADSuyiAdapterNativeMediaPlayerStatus)status{ NSLog(@"status = %zd",status); } #pragma mark - Helper 自渲染类型信息流处理方法 setUpUnifiedOnlyImageNativeAdView纯图样式 // 纯图样式 - (void)setUpUnifiedOnlyImageNativeAdView:(UIView *)adView { // 设计的adView实际大小,其中宽度和高度可以自己根据自己的需求设置 CGFloat adWidth = self.customView.frame.size.width; CGFloat adHeight = adWidth / 16.0 * 9; adView.frame = CGRectMake(0, 0, adWidth, adHeight); // 设置主图/视频(主图可选,但强烈建议带上,如果有视频试图,则必须带上) CGRect mainFrame = CGRectMake(0, 0, adWidth, adHeight); if(adView.data.shouldShowMediaView) { UIView *mediaView = [adView adsy_mediaViewForWidth:mainFrame.size.width]; mediaView.frame = mainFrame; [adView addSubview:mediaView]; } else { UIImageView *imageView = [UIImageView new]; imageView.backgroundColor = [UIColor adsy_colorWithHexString:@"#CCCCCC"]; [adView addSubview:imageView]; imageView.frame = mainFrame; NSString *urlStr = adView.data.imageUrl; if(urlStr.length > 0) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]]]; dispatch_async(dispatch_get_main_queue(), ^{ imageView.image = image; }); }); } } // 展示关闭按钮(必要) [self.customView addSubview:self.skipBtn]; self.skipBtn.frame = CGRectMake(adWidth - 12 - 54, 12, 54, 27); [self.skipBtn addTarget:self action:@selector(clickClose) forControlEvents:UIControlEventTouchUpInside]; // 显示logo图片(必要) if(![adView.adsy_platform isEqualToString:ADSuyiAdapterPlatformGDT]) { // 优量汇(广点通)会自带logo,不需要添加 UIImageView *logoImage = [UIImageView new]; [adView addSubview:logoImage]; // [adView bringSubviewToFront:logoImage]; [adView adsy_platformLogoImageDarkMode:NO loadImageBlock:^(UIImage * _Nullable image) { CGFloat maxWidth = 40; CGFloat logoHeight = maxWidth / image.size.width * image.size.height; logoImage.frame = CGRectMake(adWidth - maxWidth, adHeight - logoHeight, maxWidth, logoHeight); logoImage.image = image; }]; } } - (void)clickClose { [self.timer invalidate]; self.timer = nil; if (self.currentAdView) { [self.currentAdView adsy_close]; } } #pragma mark - ADSuyiSDKIntertitialAdDelegate /** ADSuyiSDKIntertitialAd请求成功回调 @param interstitialAd 插屏广告实例对象 */ - (void)adsy_interstitialAdSuccedToLoad:(ADSuyiSDKIntertitialAd *)interstitialAd { self.isReady = YES; if (!RQ_Video_Module.playerController.isPlaying && self.adType == RQADType_InterstitialSplash && _intertitialAd) { [_intertitialAd show]; } } /** ADSuyiSDKIntertitialAd请求失败回调 @param interstitialAd 插屏广告实例对象 @param error 失败原因 */ - (void)adsy_interstitialAdFailedToLoad:(ADSuyiSDKIntertitialAd *)interstitialAd error:(ADSuyiAdapterErrorDefine *)error { // dispatch_async(dispatch_get_main_queue(), ^{ // if (self.adType == RQADType_InterstitialSplash) { // [self resetWindow]; // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil]; // } // _intertitialAd = nil; // }); } /** ADSuyiSDKIntertitialAd展示在屏幕内回调 @param interstitialAd 插屏广告实例对象 */ - (void)adsy_interstitialAdDidPresent:(ADSuyiSDKIntertitialAd *)interstitialAd { } /** ADSuyiSDKIntertitialAd展示在屏幕内失败回调 @param interstitialAd 插屏广告实例对象 */ - (void)adsy_interstitialAdFailedToPresent:(ADSuyiSDKIntertitialAd *)interstitialAd error:(NSError *)error { // dispatch_async(dispatch_get_main_queue(), ^{ // if (self.adType == RQADType_InterstitialSplash) { // [self resetWindow]; // [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:nil]; // } // }); } /** ADSuyiSDKIntertitialAd点击回调 @param interstitialAd 插屏广告实例对象 */ - (void)adsy_interstitialAdDidClick:(ADSuyiSDKIntertitialAd *)interstitialAd { } /** ADSuyiSDKIntertitialAd关闭回调 @param interstitialAd 插屏广告实例对象 */ - (void)adsy_interstitialAdDidClose:(ADSuyiSDKIntertitialAd *)interstitialAd { // dispatch_async(dispatch_get_main_queue(), ^{ // if (self.adType == RQADType_InterstitialSplash) { // [self resetWindow]; // } // }); } /** ADSuyiSDKIntertitialAd展示回调 @param interstitialAd 广告实例 */ - (void)adsy_interstitialAdExposure:(ADSuyiSDKIntertitialAd *)interstitialAd { // if (RQ_SHARE_FUNCTION.APP_CLOSE > 0) { // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(RQ_SHARE_FUNCTION.APP_CLOSE * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // if (self.adType == RQADType_InterstitialSplash) { // [self resetWindow]; // } // }); // } } - (void)adsy_interstitialAdCloseLandingPage:(nonnull ADSuyiSDKIntertitialAd *)interstitialAd { } #pragma mark - LazyLoad - (UIView *)customView { if (!_customView) { CGRect rect; switch (self.adType) { case RQADType_Splash: rect = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT * 0.75); break; case RQADType_Banner: rect = CGRectMake(25, (RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT) - 60 - 40, RQ_SCREEN_WIDTH - 50, 50); case RQADType_Banner_IN: rect = CGRectMake(0, 0, RQ_SCREEN_WIDTH - 32.f, (RQ_SCREEN_WIDTH - 32.f) / (600 / 150.f)); default: rect = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT); break; } _customView = [[UIView alloc] initWithFrame:rect]; } return _customView; } - (ADSuyiSDKBannerAdView *)bannerView { if (!_bannerView) { // 1、初始化banner视图,并给定frame值,rate取值根据banner的尺寸 _bannerView = [[ADSuyiSDKBannerAdView alloc] initWithFrame:CGRectMake(0, 0, self.customView.width, self.customView.height)]; _bannerView.delegate = self; // 2、设置控制器,用来弹出落地页,重要 // _bannerView.controller = self.customViewController; // 3、设置广告位id,重要 if (self.adType == RQADType_Banner_IN) { _bannerView.posId = homePageBannerPlcId; CGFloat height = self.customView.width / (600 / 150.f) - (iPhone6?3.f:4.f); if (height > self.customView.height) { _bannerView.frame = CGRectMake(0, - (height - self.customView.height) / 2.f, self.customView.width, height); } else { _bannerView.frame = CGRectMake(0, (height - self.customView.height) / 2.f, self.customView.width, height); } _bannerView.backgroundColor = UIColor.clearColor; } else { CGFloat a = RQ_SCREEN_WIDTH / (640/100.0); if (self.customView.height > a) { _bannerView.posId = bannerPlcId2; } else { /// (640 / 100.f) _bannerView.posId = bannerPlcId; } // 可设置bannerview的背景色,请按需添加修改该行代码 _bannerView.backgroundColor = UIColor.whiteColor; } } return _bannerView; } - (ADSuyiSDKNativeAd *)nativeAd { if (!_nativeAd) { _nativeAd = [[ADSuyiSDKNativeAd alloc] initWithAdSize:self.customView.size]; _nativeAd.delegate = self; _nativeAd.controller = RQControllerHelper.currentViewController; _nativeAd.posId = nativeAdPlcId; } return _nativeAd; } - (ADSuyiSDKIntertitialAd *)intertitialAd { if (!_intertitialAd) { _intertitialAd = [ADSuyiSDKIntertitialAd new]; UIViewController *vc = RQControllerHelper.currentViewController.tabBarController; _intertitialAd.controller = vc; _intertitialAd.posId = (_adType == RQADType_fullScreen)? intertitialAdPlcId : intertitialSplashAdPlcId; _intertitialAd.delegate = self; _intertitialAd.tolerateTimeout = 4; // _intertitialAd.adSize = (_adType == RQADType_InterstitialSplash)? CGSizeMake(vc.view.frame.size.width / 2.f, vc.view.frame.size.height / 2.f) : CGSizeMake(vc.view.frame.size.width, vc.view.frame.size.height); } return _intertitialAd; } - (UIButton *)skipBtn { if (!_skipBtn) { _skipBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _skipBtn.frame = CGRectMake(RQ_SCREEN_WIDTH - 54 - 12, 12, 54, 27); [_skipBtn setBackgroundColor:[UIColor colorWithWhite:0.1 alpha:0.3]]; // [_skipBtn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0.1 alpha:1] size:CGSizeMake(200, 200)] forState:UIControlStateNormal]; _skipBtn.titleLabel.font = RQRegularFont(13); [_skipBtn setTitleNormal:@"跳过 5"]; _skipBtn.layer.cornerRadius = 13.5; _skipBtn.clipsToBounds = YES; } return _skipBtn; } - (NSString *)appId { return @"3299576"; } @end