ISAdInner.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // ISAdInner.m
  3. // XenonSDK
  4. //
  5. // Created by fq on 2020/12/25.
  6. // Copyright © 2020 SAGESSE. All rights reserved.
  7. //
  8. #import "ISAdInner.h"
  9. #import <IronSource/IronSource.h>
  10. #import "XSNetwork.h"
  11. @interface ISAdInner() <ISInterstitialDelegate>
  12. //是否加载好
  13. @property (nonatomic, assign)BOOL ready;
  14. @end
  15. @implementation ISAdInner
  16. - (instancetype)init
  17. {
  18. self = [super init];
  19. if (self) {
  20. self.ready = NO;
  21. self.adId = @""; //广告位名称
  22. self.agentName = @"ironsource"; //平台名称
  23. self.medium = @""; //中介
  24. self.adUnitId = @"Inter"; //原平台单元id
  25. self.type = @"Inter"; //广告类型
  26. self.unitAdId = @""; //广告组ID
  27. self.errorMsg = @""; //错误信息
  28. //init
  29. [IronSource setInterstitialDelegate:self];
  30. [IronSource loadInterstitial];
  31. }
  32. return self;
  33. }
  34. -(BOOL)isReady {
  35. return self.ready;
  36. }
  37. - (void)play:(NSString *)adId callback:(void (^)(int))back {
  38. //记录
  39. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  40. // if (self.ready) {
  41. // self.ready = NO;
  42. // }
  43. if (self.ready) {
  44. self.ready = NO;
  45. UIWindow *window = [self currentWindow];
  46. if (window) {
  47. [IronSource showInterstitialWithViewController:window.rootViewController];
  48. }
  49. back(0);
  50. }else{
  51. //广告资源未准备好
  52. [IronSource loadInterstitial];
  53. back(-1);
  54. }
  55. // //是否准备好广告资源.
  56. // if (self.ready) {
  57. // back(0);
  58. // }else{
  59. // back(-1);
  60. // }
  61. }
  62. #pragma mark - ISInterstitialDelegate
  63. - (void)interstitialDidLoad {
  64. NSLog(@"%s",__PRETTY_FUNCTION__);
  65. self.ready = YES;
  66. }
  67. - (void)interstitialDidFailToLoadWithError:(NSError *)error {
  68. NSLog(@"%s",__PRETTY_FUNCTION__);
  69. //收集错误日志上报服务器.
  70. [XSNetwork showHudFailure:@"未准备好!"];
  71. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  72. [IronSource loadInterstitial];
  73. }
  74. - (void)interstitialDidOpen {
  75. NSLog(@"%s",__PRETTY_FUNCTION__);
  76. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  77. }
  78. // The method will be called each time the Interstitial windows has opened successfully.
  79. - (void)interstitialDidShow {
  80. NSLog(@"%s",__PRETTY_FUNCTION__);
  81. }
  82. // This method gets invoked after a failed attempt to load Interstitial.
  83. // If it does happen, check out 'error' for more information and consult our
  84. // Knowledge center.
  85. - (void)interstitialDidFailToShowWithError:(NSError *)error {
  86. NSLog(@"%s",__PRETTY_FUNCTION__);
  87. //收集错误日志上报服务器.
  88. [XSNetwork showHudFailure:@"未准备好!"];
  89. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  90. [IronSource loadInterstitial];
  91. }
  92. // This method will be called each time the user had clicked the Interstitial ad.
  93. - (void)didClickInterstitial {
  94. NSLog(@"%s",__PRETTY_FUNCTION__);
  95. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  96. }
  97. // This method get invoked after the Interstitial window had closed and control
  98. // returns to your application.
  99. - (void)interstitialDidClose {
  100. NSLog(@"%s",__PRETTY_FUNCTION__);
  101. [IronSource loadInterstitial];
  102. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  103. }
  104. @end