123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // FqBUDExpressRewardedVideo.m
- // XenonSDK
- //
- // Created by fq on 2021/4/22.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqBUDExpressRewardedVideo.h"
- #import "GMTools.h"
- #import "XSNetwork.h"
- @interface FqBUDExpressRewardedVideo()<BUNativeExpressRewardedVideoAdDelegate>
- @property (nonatomic, strong) BUNativeExpressRewardedVideoAd *rewardedvideoAd;
- @property(nonatomic,assign)BOOL isVideoReadly;
- @property(nonatomic,assign)BOOL giveReward; //奖励回调
- @property(nonatomic,strong)void(^RewardedVideoCallback)(BOOL,BOOL);
- @end
- @implementation FqBUDExpressRewardedVideo
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"ChuanSANJIA"; //平台名称
- self.adUnitId = @"Rewarded";
- self.type = @"Rewarded"; //广告类型
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- self.adUnitId = [infos objectForKey:@"csj-rewarded-unitId"]; //广告组ID
- self.isVideoReadly = NO;
- self.giveReward = NO;
-
- //
- if (self.adUnitId.length == 0) {
- NSLog(@"【穿山甲广告】,error=视频激励广告广告位id为空!!!");
- }
-
-
- BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
- self.rewardedvideoAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:self.adUnitId rewardedVideoModel:model];
- // 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
- self.rewardedvideoAd.delegate = self;
- //[self loadRewardVideoAdWithSlotID:slotId];
- }
- return self;
- }
- //广告是否准备好
- -(BOOL)isAdReady {
-
- return self.isVideoReadly;
- }
- //打开广告
- -(void)openRewardedVideoAd:(NSString *)adName callback:(void (^)(BOOL,BOOL))callback {
-
- self.adId = adName;
- self.RewardedVideoCallback = callback;
-
- NSString *slotId = self.adUnitId;
- [self loadRewardVideoAdWithSlotID:slotId];
- }
- //加载广告
- - (void)loadRewardVideoAdWithSlotID:(NSString *)slotID {
-
- // BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
- // self.rewardedvideoAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:slotID rewardedVideoModel:model];
- // // 不支持中途更改代理,中途更改代理会导致接收不到广告相关回调,如若存在中途更改代理场景,需自行处理相关逻辑,确保广告相关回调正常执行。
- // self.rewardedvideoAd.delegate = self;
- [self.rewardedvideoAd 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];
-
- }
- // important: show的时候会进行WKWebview的渲染,建议一次最多展示三个广告,如果超过3个会很大概率导致WKWebview渲染失败。当然一般情况下激励视频一次只会show一个
- - (void)showRewardVideoAd {
- if (self.rewardedvideoAd) {
- UIWindow *keyWindow = [GMTools getKeyWindow];
- [self.rewardedvideoAd 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 mark - BUNativeExpressRewardedVideoAdDelegate
- - (void)nativeExpressRewardedVideoAdDidLoad:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- NSLog(@"[穿山甲]:视频激励广告素材加载成功");
- }
- - (void)nativeExpressRewardedVideoAd:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]];
-
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
- self.isVideoReadly = NO;
- self.giveReward = NO;
- if (self.RewardedVideoCallback) {
- self.RewardedVideoCallback(self.isVideoReadly,self.giveReward);
- }
-
- }
- - (void)nativeExpressRewardedVideoAdCallback:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd withType:(BUNativeExpressRewardedVideoAdType)nativeExpressVideoType{
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdDidDownLoadVideo:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- self.isVideoReadly = YES;
- self.giveReward = NO;
-
- //在此回调方法后进行广告的展示,可保证播放流畅和展示流畅,用户体验更好。
- [self showRewardVideoAd];
-
- if (self.RewardedVideoCallback) {
- self.RewardedVideoCallback(self.isVideoReadly,self.giveReward);
- }
- }
- - (void)nativeExpressRewardedVideoAdViewRenderSuccess:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdViewRenderFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]];
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
- self.isVideoReadly = NO;
- self.giveReward = NO;
- if (self.RewardedVideoCallback) {
- self.RewardedVideoCallback(self.isVideoReadly,self.giveReward);
- }
-
- }
- - (void)nativeExpressRewardedVideoAdWillVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdDidVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdWillClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdDidClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [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];
-
- //加载广告回调
- if (self.RewardedVideoCallback) {
- self.RewardedVideoCallback(self.isVideoReadly,self.giveReward);
- self.giveReward = NO;
- }
- //在此回调方法中可进行广告的置空操作.
- //同一次请求的广告最多只能计一次展示,重复的展示会被系统过滤。开发者在用户观看完广告后在nativeExpressRewardedVideoAdDidClose回调里将原来的广告对象置为nil 保证广告对象为新的请求对象
- self.rewardedvideoAd = nil;
- }
- - (void)nativeExpressRewardedVideoAdDidClick:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [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)nativeExpressRewardedVideoAdDidClickSkip:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressRewardedVideoAdDidPlayFinish:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"%@", error]];
- }
- - (void)nativeExpressRewardedVideoAdServerRewardDidSucceed:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd verify:(BOOL)verify {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"verify:%@ rewardName:%@ rewardMount:%ld",verify?@"true":@"false",rewardedVideoAd.rewardedVideoModel.rewardName,(long)rewardedVideoAd.rewardedVideoModel.rewardAmount]];
- self.giveReward = verify;
-
- //视频完整播放完成,发放奖励.
- if (self.RewardedVideoCallback) {
- self.RewardedVideoCallback(self.isVideoReadly,self.giveReward);
- }
-
- }
- - (void)nativeExpressRewardedVideoAdServerRewardDidFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd error:(NSError * _Nullable)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"rewardName:%@ rewardMount:%ld error:%@",rewardedVideoAd.rewardedVideoModel.rewardName,(long)rewardedVideoAd.rewardedVideoModel.rewardAmount,error]];
- }
- - (void)nativeExpressRewardedVideoAdDidCloseOtherController:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd 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];
- }
- #pragma mark - Log
- - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
- NSLog(@"SDKDemoDelegate BUNativeExpressRewardedVideoAd In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
- }
- @end
|