123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- //
- // 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 <AppTrackingTransparency/AppTrackingTransparency.h>//适配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 () <ADSuyiSDKBannerAdViewDelegate, ADSuyiSDKNativeAdDelegate,ADSuyiSDKIntertitialAdDelegate,
- #ifdef SUPPORT_SPLASH_ZOOMOUT
- ADSuyiSDKSplashAdZoomOutViewDelegate,
- #endif
- ADSuyiSDKSplashAdDelegate
- >
- /* 插屏广告 */
- //@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<ADSuyiAdapterNativeAdViewDelegate> *currentAdView;
- @property (nonatomic, readwrite, strong) UIView *customView;
- @property (nonatomic, readwrite, strong) UIViewController *customViewController;
- @property (nonatomic, readwrite, assign) BOOL isResume;
- @property (nonatomic, readwrite, assign) RQADType adType;
- @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 {
- [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 {
- @weakify(self)
- 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];
- [self.bannerView loadAndShow];
- if (second > 0) {
- self.bannerView.refershTime = second;
- 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];
- [self.bannerView loadAndShow];
- }
- }];
- }
- } 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;
- if (RQ_COMMON_MANAGER.JSJP_APP_AD_RATE > a) {
- self.isReady = NO;
- _intertitialAd = nil;
- [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];
- [self.bannerView loadAndShow];
- if (second > 0) {
- self.bannerView.refershTime = second;
- 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];
- [self.bannerView loadAndShow];
- }
- }];
- }
- }
- break;
- }
- default:
- break;
- }
- } else {
- switch (adType) {
- case RQADType_Splash: {
- [self loadSplashAd];
- break;
- }
- case RQADType_InterstitialSplash: {
- int a = arc4random() % 100;
- if (RQ_COMMON_MANAGER.JSJP_APP_AD_RATE > a) {
- self.isReady = NO;
- _intertitialAd = nil;
- [self.intertitialAd loadAdData];
- }
- break;
- }
- case RQADType_Banner: {
- self.bannerView.delegate = nil;
- self.bannerView = nil;
- [self.customView addSubview:self.bannerView];
- [self.bannerView loadAndShow];
- if (second > 0) {
- self.bannerView.refershTime = second;
- 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];
- [self.bannerView loadAndShow];
- }
- }];
- }
- break;
- }
- case RQADType_native: {
- [self.nativeAd load:1];
- }
- break;
- case RQADType_fullScreen: {
- self.isReady = NO;
- _intertitialAd = nil;
- [_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初始化
- [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];
- }
- // [RQNotificationCenter postNotificationName:RQADInterstitialNotificationName object:nil];
- }
- /**
- 开屏展示
-
- @param splashAd 广告实例
- */
- - (void)adsy_splashAdEffective:(ADSuyiSDKSplashAd *)splashAd{
-
- }
- #pragma mark - ADSuyiSDKBannerAdViewDelegate
- /**
- 广告获取成功
-
- @param bannerView banner实例
- */
- - (void)adsy_bannerViewDidReceived:(ADSuyiSDKBannerAdView *)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<ADSuyiAdapterNativeAdViewDelegate> *> *)adViewArray {
- for (UIView<ADSuyiAdapterNativeAdViewDelegate> *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<ADSuyiAdapterNativeAdViewDelegate> *)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<ADSuyiAdapterNativeAdViewDelegate> *)adView {
- self.currentAdView = adView;
- self.aDCloseCompletedBlock? self.aDCloseCompletedBlock(RQADDoType_Faild) : nil;
- }
- - (void)adsy_nativeAdClicked:(ADSuyiSDKNativeAd *)nativeAd
- adView:(__kindof UIView<ADSuyiAdapterNativeAdViewDelegate> *)adView {
- self.currentAdView = adView;
- [self.timer invalidate];
- self.timer = nil;
- [adView adsy_close];
- }
- - (void)adsy_nativeAdClose:(ADSuyiSDKNativeAd *)nativeAd
- adView:(__kindof UIView<ADSuyiAdapterNativeAdViewDelegate> *)adView {
- 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<ADSuyiAdapterNativeAdViewDelegate> *)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;
- }
- #pragma mark - Helper 自渲染类型信息流处理方法 setUpUnifiedOnlyImageNativeAdView纯图样式
- // 纯图样式
- - (void)setUpUnifiedOnlyImageNativeAdView:(UIView<ADSuyiAdapterNativeAdViewDelegate> *)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);
- 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
|