SPSBInfoSteamADManager.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // SPSBInfoSteamADManager.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/25.
  6. //
  7. #import "SPSBInfoSteamADManager.h"
  8. #import <JXHMacro.h>
  9. @interface SPSBInfoSteamADManager ()<BUNativeAdsManagerDelegate> {
  10. BUNativeAdsManager *_adsManager;
  11. NSMutableArray<BUNativeAd *> *_dataArray;
  12. bool _isGeting;
  13. }
  14. @end
  15. @implementation SPSBInfoSteamADManager
  16. + (instancetype)alloc {
  17. NSAssert(![self isMemberOfClass:[SPSBInfoSteamADManager class]], @"SPSBInfoSteamADManager is singleton, you should not instantiate it directly.");
  18. return [super alloc];
  19. }
  20. + (SPSBInfoSteamADManager *)shareManager {
  21. static SPSBInfoSteamADManager *manager = nil;
  22. static dispatch_once_t once;
  23. dispatch_once(&once, ^{
  24. manager = [[super allocWithZone:nil] init];
  25. });
  26. return manager;
  27. }
  28. + (instancetype)allocWithZone:(struct _NSZone *)zone {
  29. return [self shareManager];
  30. }
  31. - (instancetype)init {
  32. self = [super init];
  33. if (!self) return nil;
  34. _dataArray = NSMutableArray.new;
  35. _adsManager = BUNativeAdsManager.new;
  36. BUAdSlot *slot = BUAdSlot.new;
  37. slot.ID = @"921798067";
  38. slot.AdType = BUAdSlotAdTypeFeed;
  39. slot.position = BUAdSlotPositionTop;
  40. slot.imgSize = [BUSize sizeBy:BUProposalSize_Feed690_388];
  41. _adsManager.adslot = slot;
  42. _adsManager.delegate = self;
  43. [self loadData];
  44. return self;
  45. }
  46. - (void)loadData {
  47. _isGeting = true;
  48. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  49. [self->_adsManager loadAdDataWithCount:10];
  50. // });
  51. }
  52. - (void)nativeAdsManagerSuccessToLoad:(BUNativeAdsManager *)adsManager nativeAds:(NSArray<BUNativeAd *> *_Nullable)nativeAdDataArray {
  53. debugLog(@"feed datas load success");
  54. // debugLog(@"%@", [NSThread currentThread]);
  55. [_dataArray addObjectsFromArray:nativeAdDataArray];
  56. _isGeting = false;
  57. }
  58. - (void)nativeAdsManager:(BUNativeAdsManager *)adsManager didFailWithError:(NSError *_Nullable)error {
  59. debugLog(@"DrawVideo datas load fail----%@", error);
  60. _isGeting = false;
  61. }
  62. - (BUNativeAd *)getAdData {
  63. if (_dataArray.count == 0) {
  64. if (!_isGeting) [self loadData];
  65. return nil;
  66. }
  67. BUNativeAd *data = _dataArray[0];
  68. [_dataArray removeObjectAtIndex:0];
  69. if (_dataArray.count <= 5) [self loadData];
  70. return data;
  71. }
  72. @end
  73. SPSBInfoSteamADManager *spsb_infoSteamAdManager() {
  74. return [SPSBInfoSteamADManager shareManager];
  75. }