// // ISAdInner.m // XenonSDK // // Created by fq on 2020/12/25. // Copyright © 2020 SAGESSE. All rights reserved. // #import "ISAdInner.h" #import #import "XSNetwork.h" @interface ISAdInner() //是否加载好 @property (nonatomic, assign)BOOL ready; @end @implementation ISAdInner - (instancetype)init { self = [super init]; if (self) { self.ready = NO; self.adId = @""; //广告位名称 self.agentName = @"ironsource"; //平台名称 self.medium = @""; //中介 self.adUnitId = @"Inter"; //原平台单元id self.type = @"Inter"; //广告类型 self.unitAdId = @""; //广告组ID self.errorMsg = @""; //错误信息 //init [IronSource setInterstitialDelegate:self]; [IronSource loadInterstitial]; } 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; // } if (self.ready) { self.ready = NO; UIWindow *window = [self currentWindow]; if (window) { [IronSource showInterstitialWithViewController:window.rootViewController]; } back(0); }else{ //广告资源未准备好 [IronSource loadInterstitial]; back(-1); } // //是否准备好广告资源. // if (self.ready) { // back(0); // }else{ // back(-1); // } } #pragma mark - ISInterstitialDelegate - (void)interstitialDidLoad { NSLog(@"%s",__PRETTY_FUNCTION__); self.ready = YES; } - (void)interstitialDidFailToLoadWithError:(NSError *)error { NSLog(@"%s",__PRETTY_FUNCTION__); //收集错误日志上报服务器. [XSNetwork showHudFailure:@"未准备好!"]; self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; [IronSource loadInterstitial]; } - (void)interstitialDidOpen { 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]; } // The method will be called each time the Interstitial windows has opened successfully. - (void)interstitialDidShow { NSLog(@"%s",__PRETTY_FUNCTION__); } // This method gets invoked after a failed attempt to load Interstitial. // If it does happen, check out 'error' for more information and consult our // Knowledge center. - (void)interstitialDidFailToShowWithError:(NSError *)error { NSLog(@"%s",__PRETTY_FUNCTION__); //收集错误日志上报服务器. [XSNetwork showHudFailure:@"未准备好!"]; self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; [IronSource loadInterstitial]; } // This method will be called each time the user had clicked the Interstitial ad. - (void)didClickInterstitial { 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]; } // This method get invoked after the Interstitial window had closed and control // returns to your application. - (void)interstitialDidClose { NSLog(@"%s",__PRETTY_FUNCTION__); [IronSource loadInterstitial]; [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } @end