// // FqIronsourceInterstitial.m // XenonSDK // // Created by fq on 2021/3/29. // Copyright © 2021 SAGESSE. All rights reserved. // #import "FqIronsourceInterstitial.h" #import "XSNetwork.h" @interface FqIronsourceInterstitial() @property(nonatomic,assign)BOOL isVideoReadly; @property(nonatomic,strong)void(^InterstitialCallback)(BOOL); //广告加载报错次数统计 @property(nonatomic,assign)NSInteger errorCount; @end @implementation FqIronsourceInterstitial -(instancetype)init{ if (self = [super init]) { self.agentName = @"IronSource"; //平台名称 NSDictionary *infos = [[NSBundle mainBundle] infoDictionary]; self.adUnitId = [infos objectForKey:@"ironsource-Interstitial-unitId"]; self.type = @"Interstotal"; //广告类型 self.unitAdId = @""; //广告组ID [IronSource setInterstitialDelegate:self]; self.isVideoReadly = false; self.errorCount = 0; [IronSource loadInterstitial]; } return self; } -(BOOL)isAdReady{ return [IronSource hasInterstitial]; } -(void)openInterstitial:(NSString *)adName callback:(void (^)(BOOL))callback{ self.adId = adName; self.InterstitialCallback = callback; dispatch_async(dispatch_get_main_queue(), ^{ UIViewController *vc = [GMTools getViewControl]; [IronSource showInterstitialWithViewController:vc]; }); //数据上报 [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } #pragma mark - Interstitial Delegate Functions - (void)interstitialDidLoad { self.isVideoReadly = YES; } - (void)interstitialDidFailToLoadWithError:(NSError *)error { self.isVideoReadly = NO; //超过3次加载广告资源失败, 直接放弃加载. self.errorCount++; if (self.errorCount<=3) { [IronSource loadInterstitial]; } } - (void)interstitialDidOpen { } - (void)interstitialDidShow { if (self.InterstitialCallback) { self.InterstitialCallback(self.isVideoReadly); } self.errorCount = 0; [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; } - (void)interstitialDidFailToShowWithError:(NSError *)error { self.isVideoReadly = NO; self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo]; if (self.InterstitialCallback) { self.InterstitialCallback(self.isVideoReadly); } self.errorCount++; //超过3次加载广告资源失败, 直接放弃加载. if (self.errorCount <=3) { [IronSource loadInterstitial]; } } - (void)didClickInterstitial { [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; self.errorCount = 0; } - (void)interstitialDidClose { [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg]; self.errorCount = 0; } @end