123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- //
- // 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()<BUSplashAdDelegate, BUSplashZoomOutViewDelegate>
- @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
|