123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // FqBUDExpressInterstitial.m
- // XenonSDK
- //
- // Created by fq on 2021/4/22.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqBUDExpressInterstitial.h"
- #import "XSNetwork.h"
- #import "GMTools.h"
- @interface FqBUDExpressInterstitial()<BUNativeExpresInterstitialAdDelegate>
- @property (nonatomic, strong) BUNativeExpressInterstitialAd *interstitialAd;
- @property(nonatomic,assign)BOOL isResourceReadly;
- @property(nonatomic,strong)void(^InterstitialCallback)(BOOL);
- @end
- @implementation FqBUDExpressInterstitial
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"ChuanSANJIA"; //平台名称
- self.adUnitId = @"Interstotal";
- self.type = @"Interstotal"; //广告类型
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- self.adUnitId = [infos objectForKey:@"csj-Interstitial-unitId"]; //广告组ID
- self.isResourceReadly = NO;
- //[self loadInterstitialWithSlotID:self.adUnitId];
-
- }
- return self;
- }
- -(BOOL)isAdReady {
-
- return self.isResourceReadly;
- }
- //打开广告(未预先加载广告资源)
- -(void)openInterstitialAd:(NSString *)adName Width:(CGFloat)w Height:(CGFloat)h callback:(void (^)(BOOL))callback {
- self.adId = adName;
- self.InterstitialCallback = callback;
-
- if (!self.isResourceReadly) {
- //加载广告
- [self loadInterstitialWithSlotID:self.adUnitId Width:w Height:h];
- }
-
- }
- /***important:
- 广告加载成功的时候,会立即渲染WKWebView。
- 如果想预加载的话,建议一次最多预加载三个广告,如果超过3个会很大概率导致WKWebview渲染失败。
- */
- - (void)loadInterstitialWithSlotID:(NSString *)slotID Width:(CGFloat)w Height:(CGFloat)h{
-
- if (slotID.length == 0) {
- NSLog(@"【穿山甲广告】,error=插页广告广告位id为空!!!");
- return;
- }
-
- CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds)-40;
- CGFloat height = width/w*h;
-
- // important: 升级的用户请注意,初始化方法去掉了imgSize参数
- self.interstitialAd = [[BUNativeExpressInterstitialAd alloc] initWithSlotID:self.adUnitId adSize:CGSizeMake(width, height)];
- // 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
- self.interstitialAd.delegate = self;
- [self.interstitialAd loadAdData];
-
- //上报数据
- [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)showInterstitial {
- if (self.interstitialAd) {
-
- UIWindow *keyWindow = [GMTools getKeyWindow];
- [self.interstitialAd showAdFromRootViewController: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];
-
- }
- }
- #pragma ---BUNativeExpresInterstitialAdDelegate
- - (void)nativeExpresInterstitialAdDidLoad:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- NSLog(@"[穿山甲]:插屏广告素材加载成功");
- }
- - (void)nativeExpresInterstitialAd:(BUNativeExpressInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@", error]];
-
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
- self.isResourceReadly = NO;
- if (self.InterstitialCallback) {
- self.InterstitialCallback(self.isResourceReadly);
- }
-
- }
- - (void)nativeExpresInterstitialAdRenderSuccess:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_logWithSEL:_cmd msg:@""];
-
- //1.此回调方法中进行广告的展示,可保证播放流畅和展示流畅,用户体验更好。
- self.isResourceReadly = YES;
- [self showInterstitial];
-
- //2.广告加载回调
- if (self.InterstitialCallback) {
- self.InterstitialCallback(self.isResourceReadly);
- }
-
- }
- - (void)nativeExpresInterstitialAdRenderFail:(BUNativeExpressInterstitialAd *)interstitialAd error:(NSError *)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@", error]];
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
- self.isResourceReadly = NO;
- if (self.InterstitialCallback) {
- self.InterstitialCallback(self.isResourceReadly);
- }
- }
- - (void)nativeExpresInterstitialAdWillVisible:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpresInterstitialAdDidClick:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_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)nativeExpresInterstitialAdWillClose:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpresInterstitialAdDidClose:(BUNativeExpressInterstitialAd *)interstitialAd {
- [self pbud_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.isResourceReadly = NO;
- self.interstitialAd = nil;
-
- }
- - (void)nativeExpresInterstitialAdDidCloseOtherController:(BUNativeExpressInterstitialAd *)interstitialAd interactionType:(BUInteractionType)interactionType {
- NSString *str;
- if (interactionType == BUInteractionTypePage) {
- str = @"ladingpage";
- } else if (interactionType == BUInteractionTypeVideoAdDetail) {
- str = @"videoDetail";
- } else {
- str = @"appstoreInApp";
- }
- [self pbud_logWithSEL:_cmd msg:str];
- }
- - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
- NSLog(@"SDKDemoDelegate BUNativeExpressInterstitialAd In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
- }
- @end
|