123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- //
- // 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()<GDTExpressInterstitialAdDelegate>
- @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
|