// // FqAdsplashAdView.m // XenonSDK // // Created by fq on 2021/4/21. // Copyright © 2021 SAGESSE. All rights reserved. // #import "FqAdsplashAdView.h" #import "BUDAnimationTool.h" #import "XSNetwork.h" #import "GMTools.h" @interface FqAdsplashAdView() @property (nonatomic, assign) CFTimeInterval startTime; @property(nonatomic,assign)BOOL isVideoReadly; @property(nonatomic,strong)void(^splashAdCallback)(BOOL); @end @implementation FqAdsplashAdView -(instancetype)init{ if (self = [super init]) { self.agentName = @"ChuanSANJIA"; //平台名称 self.adUnitId = @"splash"; self.type = @"splash"; //广告类型 self.isVideoReadly = NO; NSDictionary *infos = [[NSBundle mainBundle] infoDictionary]; self.adUnitId = [infos objectForKey:@"csj-splash-unitId"]; //广告组ID CGRect frame = [UIScreen mainScreen].bounds; self.splashAdView = [[BUSplashAdView alloc] initWithSlotID:self.adUnitId frame:frame]; // tolerateTimeout = CGFLOAT_MAX , The conversion time to milliseconds will be equal to 0 self.splashAdView.tolerateTimeout = 3; self.splashAdView.delegate = self; //optional } return self; } //加载广告资源 -(void)opensplashAd:(NSString *)adName callback:(void (^)(BOOL))callback { if (self.adUnitId.length == 0) { NSLog(@"【穿山甲广告】,error=开屏广告广告位id为空!!!"); return; } self.adId = adName; self.splashAdCallback = callback; //显示广告 if (self.splashAdView) { [self.splashAdView loadAdData]; } } #pragma mark - Splash - (void)addSplashADViews { UIWindow *keyWindow = [GMTools getKeyWindow]; self.startTime = CACurrentMediaTime(); [keyWindow.rootViewController.view addSubview:self.splashAdView]; self.splashAdView.rootViewController = keyWindow.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]; } - (void)removeSplashAdView { if (self.splashAdView) { [self.splashAdView removeFromSuperview]; self.splashAdView = nil; } } #pragma mark - ========BUSplashAdDelegate============ - (void)splashAdDidLoad:(BUSplashAdView *)splashAd { [self addSplashADViews]; if (splashAd.zoomOutView) { UIWindow *keyWindow = [GMTools getKeyWindow]; UIViewController *parentVC = keyWindow.rootViewController; [parentVC.view addSubview:splashAd.zoomOutView]; [parentVC.view bringSubviewToFront:splashAd]; //Add this view to your container [parentVC.view insertSubview:splashAd.zoomOutView belowSubview:splashAd]; splashAd.zoomOutView.rootViewController = parentVC; splashAd.zoomOutView.delegate = self; } //数据上报 [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; //广告打开成功回调 self.isVideoReadly = YES; if(self.splashAdCallback){ self.splashAdCallback(self.isVideoReadly); } } - (void)splashAdDidClose:(BUSplashAdView *)splashAd { if (splashAd.zoomOutView) { [[BUDAnimationTool sharedInstance] transitionFromView:splashAd toView:splashAd.zoomOutView]; } else{ // Be careful not to say 'self.splashadview = nil' here. // Subsequent agent callbacks will not be triggered after the 'splashAdView' is released early. [splashAd removeFromSuperview]; } [self pbu_logWithSEL:_cmd msg:@""]; //数据上报 [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; self.splashAdView = nil; } - (void)splashAdDidClick:(BUSplashAdView *)splashAd { if (splashAd.zoomOutView) { [splashAd.zoomOutView removeFromSuperview]; } // Be careful not to say 'self.splashadview = nil' here. // Subsequent agent callbacks will not be triggered after the 'splashAdView' is released early. [splashAd removeFromSuperview]; [self pbu_logWithSEL:_cmd msg:@""]; //数据上报 [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)splashAdDidClickSkip:(BUSplashAdView *)splashAd { if (splashAd.zoomOutView) { [[BUDAnimationTool sharedInstance] transitionFromView:splashAd toView:splashAd.zoomOutView]; } else{ // Click Skip, there is no subsequent operation, completely remove 'splashAdView', avoid memory leak [self removeSplashAdView]; } [self pbu_logWithSEL:_cmd msg:@""]; } - (void)splashAd:(BUSplashAdView *)splashAd didFailWithError:(NSError *)error { // Display fails, completely remove 'splashAdView', avoid memory leak [self removeSplashAdView]; [self pbu_logWithSEL:_cmd msg:@""]; NSLog(@"【BUFoundation】splash Request error:%@",error); self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; //广告打开成功回调 self.isVideoReadly = NO; if(self.splashAdCallback){ self.splashAdCallback(self.isVideoReadly); } } - (void)splashAdWillVisible:(BUSplashAdView *)splashAd { [self pbu_logWithSEL:_cmd msg:@""]; } //自动关闭 - (void)splashAdWillClose:(BUSplashAdView *)splashAd { [self pbu_logWithSEL:_cmd msg:@""]; [self removeSplashAdView]; } - (void)splashAdDidCloseOtherController:(BUSplashAdView *)splashAd interactionType:(BUInteractionType)interactionType { // No further action after closing the other Controllers, completely remove the 'splashAdView' and avoid memory leaks [self removeSplashAdView]; [self pbu_logWithSEL:_cmd msg:@""]; } - (void)splashAdCountdownToZero:(BUSplashAdView *)splashAd { // When the countdown is over, it is equivalent to clicking Skip to completely remove 'splashAdView' and avoid memory leak if (!splashAd.zoomOutView) { [self removeSplashAdView]; } [self pbu_logWithSEL:_cmd msg:@""]; } #pragma mark - BUSplashZoomOutViewDelegate - (void)splashZoomOutViewAdDidClick:(BUSplashZoomOutView *)splashAd { [self pbu_logWithSEL:_cmd msg:@""]; } - (void)splashZoomOutViewAdDidClose:(BUSplashZoomOutView *)splashAd { // Click close, completely remove 'splashAdView', avoid memory leak [self removeSplashAdView]; [self pbu_logWithSEL:_cmd msg:@""]; } - (void)splashZoomOutViewAdDidAutoDimiss:(BUSplashZoomOutView *)splashAd { // Back down at the end of the countdown to completely remove the 'splashAdView' to avoid memory leaks [self removeSplashAdView]; [self pbu_logWithSEL:_cmd msg:@""]; } - (void)splashZoomOutViewAdDidCloseOtherController:(BUSplashZoomOutView *)splashAd interactionType:(BUInteractionType)interactionType { // No further action after closing the other Controllers, completely remove the 'splashAdView' and avoid memory leaks [self removeSplashAdView]; [self pbu_logWithSEL:_cmd msg:@""]; } - (void)pbu_logWithSEL:(SEL)sel msg:(NSString *)msg { CFTimeInterval endTime = CACurrentMediaTime(); NSLog(@"SplashAdView In AppDelegate (%@) total run time: %gs, extraMsg:%@", NSStringFromSelector(sel), endTime - self.startTime, msg); } @end