// // ISAdRewarded.m // XenonSDK // // Created by fq on 2020/12/25. // Copyright © 2020 SAGESSE. All rights reserved. // #import "ISAdRewarded.h" #import #import "XSNetwork.h" @interface ISAdRewarded() //是否加载好 @property (nonatomic, assign)BOOL ready; @end @implementation ISAdRewarded - (instancetype)init { self = [super init]; if (self) { self.ready = NO; self.adId = @""; //广告位名称 self.agentName = @"ironsource"; //平台名称 self.medium = @""; //中介 self.adUnitId = @"Rewarded"; //原平台单元id self.type = @"Rewarded"; //广告类型 self.unitAdId = @""; //广告组ID self.errorMsg = @""; //错误信息 //init [IronSource setRewardedVideoDelegate:self]; } return self; } - (BOOL)isReady { return self.ready; } - (void)play:(NSString *)adId callback:(void (^)(int))back { [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; if (self.ready) { self.ready = NO; self.rewardCallback = back; UIWindow *window = [self currentWindow]; if (window) { [IronSource showRewardedVideoWithViewController:window.rootViewController]; } }else{ //视频未准备好 self.rewardCallback(1); } } #pragma mark - ISRewardedVideoDelegate // This method lets you know whether or not there is a video // ready to be presented. It is only after this method is invoked // with 'hasAvailableAds' set to 'YES' that you can should 'showRV'. - (void)rewardedVideoHasChangedAvailability:(BOOL)available { NSLog(@"%s", __PRETTY_FUNCTION__); NSLog(@"ironsource ISAdRewarded rewardedVideoHasChangedAvailability :%d",available); self.ready = available; } // This method gets invoked after the user has been rewarded. - (void)didReceiveRewardForPlacement:(ISPlacementInfo *)placementInfo { NSLog(@"%s", __PRETTY_FUNCTION__); if (self.rewardCallback != nil) { self.rewardCallback(0); } } // This method gets invoked when there is a problem playing the video. // If it does happen, check out 'error' for more information and consult // our knowledge center for help. - (void)rewardedVideoDidFailToShowWithError:(NSError *)error { NSLog(@"%s", __PRETTY_FUNCTION__); [XSNetwork showHudFailure:@"未准备好!"]; //收集错误日志上报服务器. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; if (self.rewardCallback != nil) { self.rewardCallback(1); } } // This method gets invoked when we take control, but before // the video has started playing. - (void)rewardedVideoDidOpen { NSLog(@"%s", __PRETTY_FUNCTION__); [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } // This method gets invoked when we return controlback to your hands. // We chose to notify you about rewards here and not in 'didReceiveRewardForPlacement'. // This is because reward can occur in the middle of the video. - (void)rewardedVideoDidClose { NSLog(@"%s", __PRETTY_FUNCTION__); [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.rewardCallback != nil) { self.rewardCallback(2); } } // This method gets invoked when the video has started playing. - (void)rewardedVideoDidStart { NSLog(@"%s", __PRETTY_FUNCTION__); } // This method gets invoked when the video has stopped playing. - (void)rewardedVideoDidEnd { NSLog(@"%s", __PRETTY_FUNCTION__); } // This method gets invoked after a video has been clicked - (void)didClickRewardedVideo:(ISPlacementInfo *)placementInfo { NSLog(@"%s", __PRETTY_FUNCTION__); [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } @end