123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // FqGDTSplashAd.m
- // XenonSDK
- //
- // Created by fq on 2021/4/29.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqGDTSplashAd.h"
- #import "GDTSplashAd.h"
- #import "GDTSplashZoomOutView.h"
- #import "GDTSplashZoomOutView+GDTDraggable.h"
- #import "XSNetwork.h"
- #import "GMTools.h"
- @interface FqGDTSplashAd()<GDTSplashAdDelegate,GDTSplashZoomOutViewDelegate>
- @property (strong, nonatomic) GDTSplashAd *splashAd;
- @property(nonatomic,assign)BOOL isAdReadly; //广告是否准备好
- @property (retain, nonatomic) UIView *bottomView;
- @property (nonatomic, assign) BOOL isParallelLoad;
- @property (nonatomic, assign) BOOL supportZoomoutView; //视频V+
- @property(nonatomic,strong)void(^splashAdCallback)(BOOL);
- @end
- @implementation FqGDTSplashAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"YLH"; //平台名称
- self.adUnitId = @"splash";
- self.type = @"splash"; //广告类型
- self.isAdReadly = NO;
- self.isParallelLoad = NO;
- self.supportZoomoutView = NO;
-
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- if ([infos objectForKey:@"ylh-splash-unitId"]) {
- self.adUnitId = [infos objectForKey:@"ylh-splash-unitId"]; //广告组ID
- }
-
- //加载广告
- [self loadFullscreenAdWithPlacementId:self.adUnitId];
- }
- return self;
- }
- //打开广告
- -(void)opensplashAd:(NSString *)adName supportZoomoutView:(BOOL)flag callback:(void (^)(BOOL))callback {
-
- if (self.adUnitId.length == 0) {
- NSLog(@"【优量汇广告】,error=开屏广告广告位id为空!!!");
- return;
- }
- self.adId = adName;
- self.supportZoomoutView = flag;
- self.splashAd.needZoomOut = self.supportZoomoutView;
- self.splashAdCallback = callback;
-
- if (self.splashAd) {
- [self.splashAd loadFullScreenAd];
- }
-
- }
- ///拉取广告
- - (void)loadFullscreenAdWithPlacementId:(NSString *)placementId {
- if (placementId.length == 0) {
- NSLog(@"优量汇开屏广告位id为空!!!");
- return;
- }
-
- self.isParallelLoad = YES;
- self.splashAd = [[GDTSplashAd alloc] initWithPlacementId:placementId];
- self.splashAd.delegate = self;
- self.splashAd.fetchDelay = 5;
- // UIImage *splashImage = [UIImage imageNamed:@"SplashNormal"];
- // if ([self isIPhoneXSeries]) {
- // splashImage = [UIImage imageNamed:@"SplashX"];
- // } else if ([UIScreen mainScreen].bounds.size.height == 480) {
- // splashImage = [UIImage imageNamed:@"SplashSmall"];
- // }
- self.splashAd.needZoomOut = self.supportZoomoutView;
- // self.splashAd.backgroundImage = splashImage;
- self.splashAd.backgroundImage.accessibilityIdentifier = @"splash_ad";
-
- //预加载广告资源.
- [self.splashAd loadFullScreenAd];
-
- //数据上报
- [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
- }
- ///展示广告
- - (void)showFullscreenAd {
- if (!self.isParallelLoad) return;
- if (self.splashAd.isAdValid) {
- UIWindow *fK = [GMTools getKeyWindow];
- [self.splashAd showFullScreenAdInWindow:fK withLogoImage:nil skipView:nil];
-
- //数据上报
- [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- }
- }
- #pragma mark - =======GDTSplashAdDelegate========
- //广告素材加载成功
- -(void)splashAdDidLoad:(GDTSplashAd *)splashAd {
- if (splashAd.splashZoomOutView) {
- UIWindow *fK = [GMTools getKeyWindow];
- UIViewController *vc = fK.rootViewController;
- [vc.view addSubview:splashAd.splashZoomOutView];
- splashAd.splashZoomOutView.rootViewController = vc;
- // 支持拖拽
- [splashAd.splashZoomOutView supportDrag];
- }
- NSLog(@"%s", __func__);
- NSLog(@"广告拉取成功");
- NSLog(@"ecpmLevel:%@", splashAd.eCPMLevel);
-
-
- //广告拉取成功, 展示广告.
- [self showFullscreenAd];
-
- }
- -(void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- NSLog(@"广告展示成功");
-
- self.isAdReadly = YES;
- if(self.splashAdCallback){
- self.splashAdCallback(self.isAdReadly);
- }
-
- }
- //加载失败
- -(void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
- {
- NSLog(@"%s%@",__FUNCTION__,error);
- //self.splashAd = nil;
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
- if (self.isParallelLoad) {
- NSLog(@"广告展示失败");
- }else{
- NSLog(@"广告拉取失败");
- }
-
- self.isAdReadly = NO;
- if(self.splashAdCallback){
- self.splashAdCallback(self.isAdReadly);
- }
- }
- - (void)splashAdWillClosedBeforeClick:(GDTSplashAd *)splashAd {
-
- }
- - (void)splashAdDidClosedBeforeClick:(GDTSplashAd *)splashAd {
-
- }
- - (void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdWillClosed:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- -(void)splashAdClosed:(GDTSplashAd *)splashAd
- {
- //数据上报
- [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- NSLog(@"%s",__FUNCTION__);
- self.splashAd = nil;
- }
- - (void)splashAdWillPresentFullScreenModal:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdDidPresentFullScreenModal:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdExposured:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdClicked:(GDTSplashAd *)splashAd
- {
- //数据上报
- [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- if (splashAd.splashZoomOutView) {
- [splashAd.splashZoomOutView removeFromSuperview];
- }
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdWillDismissFullScreenModal:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashAdDidDismissFullScreenModal:(GDTSplashAd *)splashAd
- {
- NSLog(@"%s",__FUNCTION__);
- }
- #pragma mark - GDTSplashZoomOutViewDelegate
- - (void)splashZoomOutViewDidClick:(GDTSplashZoomOutView *)splashZoomOutView
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashZoomOutViewAdDidClose:(GDTSplashZoomOutView *)splashZoomOutView
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashZoomOutViewAdVideoFinished:(GDTSplashZoomOutView *)splashZoomOutView
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashZoomOutViewAdDidPresentFullScreenModal:(GDTSplashZoomOutView *)splashZoomOutView
- {
- NSLog(@"%s",__FUNCTION__);
- }
- - (void)splashZoomOutViewAdDidDismissFullScreenModal:(GDTSplashZoomOutView *)splashZoomOutView
- {
- NSLog(@"%s",__FUNCTION__);
- }
- #pragma mark - Private Method
- -(BOOL)isIPhoneXSeries {
- if (@available(iOS 11.0, *)) {
- UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
- if (mainWindow.safeAreaInsets.bottom > 0.0) {
- return YES;
- }
- }
- return NO;
- }
- @end
|