FqIronsourceBanner.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // FqIronsourceBanner.m
  3. // QQQ
  4. //
  5. // Created by Mgs on 2020/12/7.
  6. //
  7. #import "FqIronsourceBanner.h"
  8. #import "XSNetwork.h"
  9. @interface FqIronsourceBanner()<ISBannerDelegate>
  10. @end
  11. @implementation FqIronsourceBanner
  12. -(instancetype)init{
  13. if (self = [super init]) {
  14. self.agentName = @"IronSource"; //平台名称
  15. self.adUnitId = @"ironBanner";
  16. self.type = @"Banner"; //广告类型
  17. self.unitAdId = @""; //广告组ID
  18. [IronSource setBannerDelegate:self];
  19. }
  20. return self;
  21. }
  22. -(void)openWithSuperView:(UIView *)container{
  23. dispatch_async(dispatch_get_main_queue(), ^{
  24. if (self.bannerView) {
  25. [IronSource destroyBanner:self.bannerView];
  26. }
  27. self.bannerContainer = container;
  28. UIViewController *vc = [GMTools getViewControl];
  29. [IronSource loadBannerWithViewController:vc size:ISBannerSize_BANNER];
  30. });
  31. //数据上报
  32. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  33. }
  34. /**
  35. Called after a banner ad has been successfully loaded
  36. */
  37. - (void)bannerDidLoad:(ISBannerView *)bannerView{
  38. dispatch_async(dispatch_get_main_queue(), ^{
  39. self.bannerView = bannerView;
  40. [bannerView removeFromSuperview];
  41. [self.bannerContainer addSubview:bannerView];
  42. CGSize size = [UIScreen mainScreen].bounds.size;
  43. bannerView.frame = CGRectMake(0, 0, size.width, size.width/320.0*50);
  44. });
  45. //数据上报
  46. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  47. }
  48. /**
  49. Called after a banner has attempted to load an ad but failed.
  50. @param error The reason for the error
  51. */
  52. - (void)bannerDidFailToLoadWithError:(NSError *)error{
  53. //收集错误日志上报服务器.
  54. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  55. dispatch_async(dispatch_get_main_queue(), ^{
  56. for (UIView *vi in self.bannerContainer.subviews) {
  57. [vi removeFromSuperview];
  58. }
  59. self.bannerContainer.hidden = true;
  60. });
  61. }
  62. /**
  63. Called after a banner has been clicked.
  64. */
  65. - (void)didClickBanner{
  66. //数据上报
  67. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  68. }
  69. /**
  70. Called when a banner is about to present a full screen content.
  71. */
  72. - (void)bannerWillPresentScreen{
  73. }
  74. /**
  75. Called after a full screen content has been dismissed.
  76. */
  77. - (void)bannerDidDismissScreen{
  78. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  79. }
  80. /**
  81. Called when a user would be taken out of the application context.
  82. */
  83. - (void)bannerWillLeaveApplication{
  84. }
  85. @end