123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //
- // FqToPONRewardedVideoAd.m
- // XenonSDK
- //
- // Created by fq on 2021/5/12.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqToPONRewardedVideoAd.h"
- #import <AnyThinkRewardedVideo/AnyThinkRewardedVideo.h>
- #import "XSNetwork.h"
- #import "GMTools.h"
- @interface FqToPONRewardedVideoAd()<ATRewardedVideoDelegate>
- @property(nonatomic,assign)BOOL isAdReadly; //广告是否准备好
- @property(nonatomic,assign)BOOL isReward; //是否发放奖励
- @property(nonatomic,strong)void(^rewardVideoAdCallback)(BOOL,BOOL);
- @end
- @implementation FqToPONRewardedVideoAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"TopOn"; //平台名称
- self.adUnitId = @"Rewarded";
- self.type = @"Rewarded"; //广告类型
- self.isAdReadly = NO;
- self.isReward = NO;
-
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- if ([infos objectForKey:@"topon-rewarded-unitId"]) {
- self.adUnitId = [infos objectForKey:@"topon-rewarded-unitId"]; //广告组ID
- }
-
- //1.程序启动时,加载广告.
- [self loadRewardedVideoAdWithPlacementId:self.adUnitId];
- }
- return self;
- }
- //广告是否准备好
- -(BOOL)isAdReadly {
- if ([[ATAdManager sharedManager] rewardedVideoReadyForPlacementID:self.adUnitId]) {
- return YES;
- } else {
- return NO;
- }
- return NO;
- }
- //打开广告
- -(void)openRewardedVideoAd:(NSString *)adName callback:(void (^)(BOOL, BOOL))callback {
- if (self.adUnitId.length == 0) {
- NSLog(@"【ToPon广告】,error=视频激励广告广告位id为空!!!");
- [XSNetwork showHudFailure:@"广告位id为空!"];
- return;
- }
- self.adId = adName;
- self.rewardVideoAdCallback = callback;
-
- //判断广告是否准备好.
- if([self isAdReadly]){
- //广告准备好,展示广告.
- UIViewController *vc = [GMTools getViewControl];
- [[ATAdManager sharedManager] showRewardedVideoWithPlacementID:self.adUnitId inViewController:vc delegate:self];
- }else{
- //无广告可展示,加载广告.
- //PS:重新加载广告,考虑一直广告加载失败的情况,超过3次加载广告失败,不做任何处理.不然会死循环.
- [self loadRewardedVideoAdWithPlacementId:self.adUnitId];
- [XSNetwork showHudSuccess:@"广告正在加载中"];
- }
- }
- //加载广告资源
- -(void)loadRewardedVideoAdWithPlacementId:(NSString *)placementId {
- //注:在加载facebook广告的时候一定要传入userid,以获取激励视频回调. extra:@{kATAdLoadingExtraUserIDKey:@"test_user_id"}
- [[ATAdManager sharedManager] loadADWithPlacementID:self.adUnitId extra:nil delegate:self];
-
- }
- #pragma mark - =============ATRewardedVideoDelegate==============
- -(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
- NSLog(@"RV: didFinishLoadingADWithPlacementID");
-
- self.isAdReadly = YES;
- if (self.rewardVideoAdCallback) {
- self.rewardVideoAdCallback(self.isAdReadly, self.isReward);
- }
-
- }
- -(void) didFailToLoadADWithPlacementID:(NSString* )placementID error:(NSError *)error {
- NSLog(@"RV: failed to load:%@", error);
-
- self.isAdReadly = NO;
- self.isReward = NO;
- if (self.rewardVideoAdCallback) {
- self.rewardVideoAdCallback(self.isAdReadly, self.isReward);
- }
-
- }
- -(void) rewardedVideoDidRewardSuccessForPlacemenID:(NSString *)placementID extra:(NSDictionary *)extra{
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidRewardSuccessForPlacemenID:%@ extra:%@",placementID,extra);
- }
- -(void) rewardedVideoDidStartPlayingForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidStartPlayingForPlacementID:%@ extra:%@", placementID, extra);
- }
- -(void) rewardedVideoDidEndPlayingForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidEndPlayingForPlacementID:%@ extra:%@", placementID, extra);
-
- }
- -(void) rewardedVideoDidFailToPlayForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary *)extra {
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidFailToPlayForPlacementID:%@ error:%@ extra:%@", placementID, error, extra);
- }
- -(void) rewardedVideoDidCloseForPlacementID:(NSString*)placementID rewarded:(BOOL)rewarded extra:(NSDictionary *)extra {
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidCloseForPlacementID:%@, rewarded:%@ extra:%@", placementID, rewarded ? @"yes" : @"no", extra);
- self.isAdReadly = YES;
- self.isReward = rewarded;
- if (self.rewardVideoAdCallback) {
- self.rewardVideoAdCallback(YES, self.isReward);
- }
- }
- -(void) rewardedVideoDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONRewardedVideoAd.m::rewardedVideoDidClickForPlacementID:%@ extra:%@", placementID, extra);
- }
- - (void)rewardedVideoDidDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
-
- }
- @end
|