123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // ISAdRewarded.m
- // XenonSDK
- //
- // Created by fq on 2020/12/25.
- // Copyright © 2020 SAGESSE. All rights reserved.
- //
- #import "ISAdRewarded.h"
- #import <IronSource/IronSource.h>
- #import "XSNetwork.h"
- @interface ISAdRewarded()<ISRewardedVideoDelegate>
- //是否加载好
- @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
|