123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- #import "FqBUDExpressNativeAd.h"
- #import "GMTools.h"
- #import "XSNetwork.h"
- @interface FqBUDExpressNativeAd()<BUNativeExpressAdViewDelegate>
- @property (strong, nonatomic) NSMutableArray<__kindof BUNativeExpressAdView *> *expressAdViews;
- @property (strong, nonatomic) BUNativeExpressAdManager *nativeExpressAdManager;
- @property (strong, nonatomic) NSTimer *timer;
- @property(nonatomic,assign)CGRect rect1;
- @property(nonatomic,assign)NSInteger viewSize;
- @property(nonatomic,assign)BOOL isResourceReadly;
- @property(nonatomic,strong)void(^nativeCallback)(BOOL);
- @end
- @implementation FqBUDExpressNativeAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"ChuanSANJIA";
- self.adUnitId = @"native";
- self.type = @"native";
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- self.adUnitId = [infos objectForKey:@"csj-native-unitId"];
- self.isResourceReadly = NO;
-
-
-
- }
- return self;
- }
- -(BOOL)isAdReady {
-
- return self.isResourceReadly;
- }
- -(void)openNativeAd:(NSString *)adName WidthCGRect:(CGRect)rect BUSize:(NSInteger)size callback:(void (^)(BOOL))callback {
- self.adId = adName;
- self.nativeCallback = callback;
-
- self.rect1 = rect;
- self.viewSize = size;
-
-
- [self loadNativeAdWithSlotID:self.adUnitId CGRect:rect BUSize:size];
-
- }
- - (void)loadNativeAdWithSlotID:(NSString *)slotId CGRect:(CGRect)rect BUSize:(NSInteger)size{
- if (slotId.length == 0) {
- NSLog(@"【穿山甲广告】,error=原生广告广告位id为空!!!");
- return;
- }
-
- if (!self.expressAdViews) {
- self.expressAdViews = [NSMutableArray arrayWithCapacity:20];
- }
- BUAdSlot *slot1 = [[BUAdSlot alloc] init];
-
- slot1.ID = slotId;
- slot1.AdType = BUAdSlotAdTypeFeed;
- slot1.supportRenderControl = YES;
-
- BUSize *imgSize = [BUSize sizeBy:size];
- slot1.imgSize = imgSize;
- slot1.position = BUAdSlotPositionFeed;
-
-
- if (!self.nativeExpressAdManager) {
-
- self.nativeExpressAdManager = [[BUNativeExpressAdManager alloc] initWithSlot:slot1 adSize:CGSizeMake(rect.size.width, rect.size.height)];
- }
-
- self.nativeExpressAdManager.delegate = self;
-
-
- NSInteger count = 2;
- [self.nativeExpressAdManager loadAdDataWithCount:count];
-
-
- [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
- }
- #pragma mark - BUNativeExpressAdViewDelegate
- - (void)nativeExpressAdSuccessToLoad:(BUNativeExpressAdManager *)nativeExpressAd views:(NSArray<__kindof BUNativeExpressAdView *> *)views {
- [self.expressAdViews removeAllObjects];
- if (views.count) {
-
- [self.expressAdViews addObjectsFromArray:views];
- UIWindow *keyWindow = [GMTools getKeyWindow];
- [views enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- BUNativeExpressAdView *expressView = (BUNativeExpressAdView *)obj;
- expressView.rootViewController = keyWindow.rootViewController;
-
- [expressView render];
- }];
- }
-
- UIViewController *v1 = [GMTools getViewControl];
- BUNativeExpressAdView *childView = (BUNativeExpressAdView *)[self.expressAdViews firstObject];
-
- childView.center = CGPointMake(self.rect1.origin.x, self.rect1.origin.y);
-
- [v1.view addSubview:childView];
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressAdFailToLoad:(BUNativeExpressAdManager *)nativeExpressAd error:(NSError *)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@", error]];
-
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
-
- self.isResourceReadly = NO;
-
- }
- - (void)nativeExpressAdViewRenderSuccess:(BUNativeExpressAdView *)nativeExpressAdView {
- UIViewController *v1 = [GMTools getViewControl];
- BUNativeExpressAdView *childView = (BUNativeExpressAdView *)[self.expressAdViews firstObject];
- childView.center = CGPointMake(self.rect1.origin.x, self.rect1.origin.y);
- [v1.view addSubview:childView];
-
-
- self.isResourceReadly = YES;
- if (self.nativeCallback) {
- self.nativeCallback(self.isResourceReadly);
- }
-
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCurrentPlayedTime) userInfo:nil repeats:YES];
- [self.timer fire];
- });
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"nativeExpressAdView.videoDuration:%ld", (long)nativeExpressAdView.videoDuration]];
- }
- - (void)updateCurrentPlayedTime {
- for (BUNativeExpressAdView *nativeExpressAdView in self.expressAdViews) {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"nativeExpressAdView.currentPlayedTime:%.4f", nativeExpressAdView.currentPlayedTime]];
- }
- }
- - (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView stateDidChanged:(BUPlayerPlayState)playerState {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"playerState:%ld", (long)playerState]];
- }
- - (void)nativeExpressAdViewRenderFail:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {
- [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@ 此广告将会从列表中移除", error]];
- [self.expressAdViews removeObject:nativeExpressAdView];
- UIViewController *v1 = [GMTools getViewControl];
- if (self.expressAdViews.count > 0) {
- [v1.view addSubview:[self.expressAdViews firstObject]];
- }
-
- self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
-
-
- self.isResourceReadly = NO;
- if (self.nativeCallback) {
- self.nativeCallback(self.isResourceReadly);
- }
-
- }
- - (void)nativeExpressAdViewWillShow:(BUNativeExpressAdView *)nativeExpressAdView {
- [self pbud_logWithSEL:_cmd msg:@""];
-
-
- [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- }
- - (void)nativeExpressAdViewDidClick:(BUNativeExpressAdView *)nativeExpressAdView {
- [self pbud_logWithSEL:_cmd msg:@""];
-
-
- [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- }
- - (void)nativeExpressAdViewPlayerDidPlayFinish:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView dislikeWithReason:(NSArray<BUDislikeWords *> *)filterWords {
- [self.expressAdViews removeObject:nativeExpressAdView];
- [nativeExpressAdView removeFromSuperview];
- [self pbud_logWithSEL:_cmd msg:@""];
-
- self.nativeExpressAdManager = nil;
-
- }
- - (void)nativeExpressAdViewDidClosed:(BUNativeExpressAdView *)nativeExpressAdView {
- [self pbud_logWithSEL:_cmd msg:@""];
-
-
- self.nativeExpressAdManager = nil;
-
- [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
-
- }
- - (void)nativeExpressAdViewWillPresentScreen:(BUNativeExpressAdView *)nativeExpressAdView {
- [self pbud_logWithSEL:_cmd msg:@""];
- }
- - (void)nativeExpressAdViewDidCloseOtherController:(BUNativeExpressAdView *)nativeExpressAdView interactionType:(BUInteractionType)interactionType {
- NSString *str;
- if (interactionType == BUInteractionTypePage) {
- str = @"ladingpage";
- } else if (interactionType == BUInteractionTypeVideoAdDetail) {
- str = @"videoDetail";
- } else {
- str = @"appstoreInApp";
- }
- [self pbud_logWithSEL:_cmd msg:str];
- }
- - (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
- NSLog(@"SDKDemoDelegate BUNativeExpressFeedAdView In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
- }
- @end
|