FqIronsourceInterstitial.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // FqIronsourceInterstitial.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2021/3/29.
  6. // Copyright © 2021 SAGESSE. All rights reserved.
  7. //
  8. #import "FqIronsourceInterstitial.h"
  9. #import "XSNetwork.h"
  10. @interface FqIronsourceInterstitial()<ISInterstitialDelegate>
  11. @property(nonatomic,assign)BOOL isVideoReadly;
  12. @property(nonatomic,strong)void(^InterstitialCallback)(BOOL);
  13. //广告加载报错次数统计
  14. @property(nonatomic,assign)NSInteger errorCount;
  15. @end
  16. @implementation FqIronsourceInterstitial
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.agentName = @"IronSource"; //平台名称
  20. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  21. self.adUnitId = [infos objectForKey:@"ironsource-Interstitial-unitId"];
  22. self.type = @"Interstotal"; //广告类型
  23. self.unitAdId = @""; //广告组ID
  24. [IronSource setInterstitialDelegate:self];
  25. self.isVideoReadly = false;
  26. self.errorCount = 0;
  27. [IronSource loadInterstitial];
  28. }
  29. return self;
  30. }
  31. -(BOOL)isAdReady{
  32. return [IronSource hasInterstitial];
  33. }
  34. -(void)openInterstitial:(NSString *)adName callback:(void (^)(BOOL))callback{
  35. self.adId = adName;
  36. self.InterstitialCallback = callback;
  37. dispatch_async(dispatch_get_main_queue(), ^{
  38. UIViewController *vc = [GMTools getViewControl];
  39. [IronSource showInterstitialWithViewController:vc];
  40. });
  41. //数据上报
  42. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  43. }
  44. #pragma mark - Interstitial Delegate Functions
  45. - (void)interstitialDidLoad {
  46. self.isVideoReadly = YES;
  47. }
  48. - (void)interstitialDidFailToLoadWithError:(NSError *)error {
  49. self.isVideoReadly = NO;
  50. //超过3次加载广告资源失败, 直接放弃加载.
  51. self.errorCount++;
  52. if (self.errorCount<=3) {
  53. [IronSource loadInterstitial];
  54. }
  55. }
  56. - (void)interstitialDidOpen {
  57. }
  58. - (void)interstitialDidShow {
  59. if (self.InterstitialCallback) {
  60. self.InterstitialCallback(self.isVideoReadly);
  61. }
  62. self.errorCount = 0;
  63. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  64. }
  65. - (void)interstitialDidFailToShowWithError:(NSError *)error {
  66. self.isVideoReadly = NO;
  67. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  68. if (self.InterstitialCallback) {
  69. self.InterstitialCallback(self.isVideoReadly);
  70. }
  71. self.errorCount++;
  72. //超过3次加载广告资源失败, 直接放弃加载.
  73. if (self.errorCount <=3) {
  74. [IronSource loadInterstitial];
  75. }
  76. }
  77. - (void)didClickInterstitial {
  78. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  79. self.errorCount = 0;
  80. }
  81. - (void)interstitialDidClose {
  82. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  83. self.errorCount = 0;
  84. }
  85. @end