123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // SPSBInfoSteamADManager.m
- // 我的社保
- //
- // Created by shanp on 2021/4/25.
- //
- #import "SPSBInfoSteamADManager.h"
- #import <JXHMacro.h>
- @interface SPSBInfoSteamADManager ()<BUNativeAdsManagerDelegate> {
- BUNativeAdsManager *_adsManager;
- NSMutableArray<BUNativeAd *> *_dataArray;
- bool _isGeting;
- }
- @end
- @implementation SPSBInfoSteamADManager
- + (instancetype)alloc {
- NSAssert(![self isMemberOfClass:[SPSBInfoSteamADManager class]], @"SPSBInfoSteamADManager is singleton, you should not instantiate it directly.");
- return [super alloc];
- }
- + (SPSBInfoSteamADManager *)shareManager {
- static SPSBInfoSteamADManager *manager = nil;
- static dispatch_once_t once;
- dispatch_once(&once, ^{
- manager = [[super allocWithZone:nil] init];
- });
-
- return manager;
- }
- + (instancetype)allocWithZone:(struct _NSZone *)zone {
- return [self shareManager];
- }
- - (instancetype)init {
- self = [super init];
- if (!self) return nil;
- _dataArray = NSMutableArray.new;
- _adsManager = BUNativeAdsManager.new;
- BUAdSlot *slot = BUAdSlot.new;
- slot.ID = @"921798067";
- slot.AdType = BUAdSlotAdTypeFeed;
- slot.position = BUAdSlotPositionTop;
- slot.imgSize = [BUSize sizeBy:BUProposalSize_Feed690_388];
- _adsManager.adslot = slot;
- _adsManager.delegate = self;
-
- [self loadData];
- return self;
- }
- - (void)loadData {
- _isGeting = true;
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- [self->_adsManager loadAdDataWithCount:10];
- // });
-
- }
- - (void)nativeAdsManagerSuccessToLoad:(BUNativeAdsManager *)adsManager nativeAds:(NSArray<BUNativeAd *> *_Nullable)nativeAdDataArray {
- debugLog(@"feed datas load success");
- // debugLog(@"%@", [NSThread currentThread]);
- [_dataArray addObjectsFromArray:nativeAdDataArray];
- _isGeting = false;
- }
- - (void)nativeAdsManager:(BUNativeAdsManager *)adsManager didFailWithError:(NSError *_Nullable)error {
- debugLog(@"DrawVideo datas load fail----%@", error);
- _isGeting = false;
- }
- - (BUNativeAd *)getAdData {
- if (_dataArray.count == 0) {
- if (!_isGeting) [self loadData];
- return nil;
- }
- BUNativeAd *data = _dataArray[0];
- [_dataArray removeObjectAtIndex:0];
- if (_dataArray.count <= 5) [self loadData];
- return data;
- }
- @end
- SPSBInfoSteamADManager *spsb_infoSteamAdManager() {
- return [SPSBInfoSteamADManager shareManager];
- }
|