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