// // FqGDTExpressInterstitialAd.m // XenonSDK // // Created by fq on 2021/4/29. // Copyright © 2021 SAGESSE. All rights reserved. // #import "FqGDTExpressInterstitialAd.h" #import "GDTExpressInterstitialAd.h" #import "GMTools.h" #import "XSNetwork.h" @interface FqGDTExpressInterstitialAd() @property (nonatomic, strong) GDTExpressInterstitialAd *interstitial; @property(nonatomic,assign)BOOL isAdReadly; //广告是否准备好 @property(nonatomic,strong)void(^InterstitialAdCallback)(BOOL); @end @implementation FqGDTExpressInterstitialAd -(instancetype)init{ if (self = [super init]) { self.agentName = @"YLH"; //平台名称 self.adUnitId = @"Interstotal"; self.type = @"Interstotal"; //广告类型 self.isAdReadly = NO; NSDictionary *infos = [[NSBundle mainBundle] infoDictionary]; if ([infos objectForKey:@"ylh-Interstitial-unitId"]) { self.adUnitId = [infos objectForKey:@"ylh-Interstitial-unitId"]; //广告组ID } if (self.adUnitId.length == 0) { NSLog(@"【优量汇广告】,error=模板2插屏半屏广告位id为空!!!"); } //预加载广告资源 [self loadExpressInterstitialAdWithPlacementId:self.adUnitId]; } return self; } //打开广告 -(void)openInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback { self.adId = adName; self.InterstitialAdCallback = callback; if (self.interstitial) { [self.interstitial loadHalfScreenAd]; } } //拉取广告 - (void)loadExpressInterstitialAdWithPlacementId:(NSString *)placementId { if (placementId.length == 0) { NSLog(@"[优量汇SDK],模板2插屏半屏广告id为空!!!"); return; } if (self.interstitial) { self.interstitial.delegate = nil; } self.interstitial = [[GDTExpressInterstitialAd alloc] initWithPlacementId:placementId]; self.interstitial.delegate = self; self.interstitial.videoMuted = YES; // 设置视频是否Mute,默认自动播放下静音 self.interstitial.videoAutoPlayOnWWAN = NO; // 设置视频是否在非 WiFi 网络自动播放 //self.interstitial.maxVideoDuration = 30; // 如果需要设置视频最大时长,可以通过这个参数来进行设置 //数据上报 [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)showInterstitialAd { UIWindow *fK = [GMTools getKeyWindow]; [self.interstitial presentHalfScreenAdFromRootViewController:fK.rootViewController]; //数据上报 [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 - =========GDTExpressInterstitialAdDelegate=========== /** * 模板插屏半屏广告加载成功回调 * 当接收服务器返回的广告数据成功且模板渲染成功后调用该函数 */ - (void)expressInterstitialSuccessToLoadAd:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Load Success." ]); NSLog(@"videoDuration:%lf isVideo: %@", unifiedInterstitial.videoDuration, @(unifiedInterstitial.isVideoAd)); [self showInterstitialAd]; } /** * 模板插屏半屏广告预加载失败回调 * 当接收服务器返回的广告数据失败或模板渲染失败后调用该函数 */ - (void)expressInterstitialFailToLoadAd:(GDTExpressInterstitialAd *)unifiedInterstitial error:(NSError *)error { NSLog(@"%s",__FUNCTION__); NSLog(@"interstitial fail to load, Error : %@",error); self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; //回调 self.isAdReadly = NO; if(self.InterstitialAdCallback){ self.InterstitialAdCallback(self.isAdReadly); } } /** * 模板插屏半屏广告将要展示回调 * 模板插屏半屏广告即将展示回调该函数 */ - (void)expressInterstitialWillPresentScreen:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Going to present." ]); } /** * 模板插屏半屏广告展示失败回调 * 模板插屏半屏展示失败时回调该函数 */ - (void)expressInterstitialFailToPresent:(GDTExpressInterstitialAd *)unifiedInterstitial error:(NSError *)error { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"fail to present." ]); self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; self.isAdReadly = NO; if(self.InterstitialAdCallback){ self.InterstitialAdCallback(self.isAdReadly); } } /** * 模板插屏半屏广告视图展示成功回调 * 模板插屏半屏广告展示成功回调该函数 */ - (void)expressInterstitialDidPresentScreen:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Success Presented." ]); self.isAdReadly = YES; if(self.InterstitialAdCallback){ self.InterstitialAdCallback(self.isAdReadly); } } /** * 模板插屏半屏广告展示结束回调 * 模板插屏半屏广告展示结束回调该函数 */ - (void)expressInterstitialDidDismissScreen:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Finish Presented." ]); self.interstitial = nil; } /** * 当点击下载应用时会调用系统程序打开 */ - (void)expressInterstitialWillLeaveApplication:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); NSLog(@"%@",[NSString stringWithFormat:@"插屏状态:%@",@"Application enter background." ]); } /** * 模板插屏半屏广告曝光回调 */ - (void)expressInterstitialWillExposure:(GDTExpressInterstitialAd *)expressInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏广告点击回调 */ - (void)expressInterstitialClicked:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); //数据上报 [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } /** * 点击模板插屏半屏广告以后即将弹出全屏广告页 */ - (void)expressInterstitialAdWillPresentFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 点击模板插屏半屏广告以后弹出全屏广告页 */ - (void)expressInterstitialAdDidPresentFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 全屏广告页将要关闭 */ - (void)expressInterstitialAdWillDismissFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 全屏广告页被关闭 */ - (void)expressInterstitialAdDidDismissFullScreenModal:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏视频广告 player 播放状态更新回调 */ - (void)expressInterstitialAd:(GDTExpressInterstitialAd *)unifiedInterstitial playerStatusChanged:(GDTMediaPlayerStatus)status { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏视频广告详情页 WillPresent 回调 */ - (void)expressInterstitialAdViewWillPresentVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏视频广告详情页 DidPresent 回调 */ - (void)expressInterstitialAdViewDidPresentVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏视频广告详情页 WillDismiss 回调 */ - (void)expressInterstitialAdViewWillDismissVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } /** * 模板插屏半屏视频广告详情页 DidDismiss 回调 */ - (void)expressInterstitialAdViewDidDismissVideoVC:(GDTExpressInterstitialAd *)unifiedInterstitial { NSLog(@"%s",__FUNCTION__); } @end