ios – Facebook原生广告没有调用FBNativeAdsManagerDelegate实现方法

ios – Facebook原生广告没有调用FBNativeAdsManagerDelegate实现方法,第1张

概述Facebook Native Ads中的FBNativeAdsManagerDelegate在UIViewController类中正常工作,但在自定义NSObject类中使用时,它无法正常工作,即其委托方法nativeAdsLoaded和nativeAdsFailedToLoadWithError未被调用. CustomFBAd.h文件 @import FBAudienceNetwork;# Facebook Native Ads中的FBNativeAdsManagerDelegate在UIVIEwController类中正常工作,但在自定义NSObject类中使用时,它无法正常工作,即其委托方法nativeAdsLoaded和nativeAdsFailedToloaDWithError未被调用.

CustomFBAd.h文件

@import FBAudIEnceNetwork;#import <Foundation/Foundation.h>@protocol OnFBNativeAdLoadedDelegate<NSObject>- (voID)onFBNativeAdLoaded:(UIVIEw *)adVIEw;@end@interface CustomFBAd : NSObject@property (nonatomic,weak) ID <OnFBNativeAdLoadedDelegate>delegate;-(voID)requestNativeAd:(Nsstring *)FaceBookPlacementID;@end

CustomFBAd.m文件

#import "CustomFBAd.h"@interface CustomFBAd ()<FBNativeAdsManagerDelegate,FBNativeAdDelegate>@property (nonatomic,strong) FBNativeAdsManager *manager;@property (nonatomic,weak) FBNativeAdScrollVIEw *scrollVIEw;@end@implementation CustomFBAd-(voID)requestNativeAd:(Nsstring *)FaceBookPlacementID{    if(FaceBookPlacementID.length != 0){        FBNativeAdsManager *manager = [[FBNativeAdsManager alloc] initWithPlacementID:FaceBookPlacementID forNumAdsRequested:5];        manager.delegate = self;        [FBAdSettings addTestDevice:@"cf1bb93becbe6e31f26fdf7d80d19b4ae225afaa"];        [manager loadAds];        self.manager = manager;    }}#pragma mark - FBNativeAdDelegate implementation- (voID)nativeAdDIDClick:(FBNativeAd *)nativeAd{    //    NSLog(@"Native ad was clicked.");}- (voID)nativeAdDIDFinishHandlingClick:(FBNativeAd *)nativeAd{    //    NSLog(@"Native ad dID finish click handling.");}- (voID)nativeADWillLogImpression:(FBNativeAd *)nativeAd{    //    NSLog(@"Native ad impression is being captured.");}#pragma mark FBNativeAdsManagerDelegate-(voID)nativeAdDIDLoad:(FBNativeAd *)nativeAd{}- (voID)nativeAdsLoaded{    NSLog(@"Native ads loaded,constructing native UI...");    if (self.scrollVIEw) {        [self.scrollVIEw removeFromSupervIEw];        self.scrollVIEw = nil;    }    FBNativeAdScrollVIEw *scrollVIEw = [[FBNativeAdScrollVIEw alloc] initWithNativeAdsManager:self.manager withType:FBNativeAdVIEwTypeGenericHeight120];    scrollVIEw.xInset = 0;    scrollVIEw.delegate = self;    self.scrollVIEw = scrollVIEw;    [self.delegate onFBNativeAdLoaded:self.scrollVIEw];}- (voID)nativeAdsFailedToloaDWithError:(NSError *)error{    NSLog(@"Native ads Failed to load with error: %@",error);}@end

如上面的代码所述,我在requestNativeAd方法中设置了FBNativeAdsManager的委托

manager.delegate = self;

并且还用作FBNativeAdsManagerDelegate,FBNativeAdDelegate

@interface CustomFBAd ()<FBNativeAdsManagerDelegate,FBNativeAdDelegate>

并将此代码称为

CustomFBAd *objFBAd = [[CustomFBAd alloc]init];    objFBAd.delegate = self;    [objFBAd requestNativeAd:@"my_FB_placement_ID"];

任何线索(注意:如果我在UIVIEwController中使用它,相同的代码可以工作)?谢谢

解决方法 如果你的委托方法是在uivIEwcontroller中调用的,那么代码就会出现问题.我想你必须在你的控制器中有一个强大的CustomFBAd参考.因为其他参考文献都没有抓住您的CustomFBAd.希望能帮助到你 总结

以上是内存溢出为你收集整理的ios – Facebook原生广告没有调用FBNativeAdsManagerDelegate实现方法全部内容,希望文章能够帮你解决ios – Facebook原生广告没有调用FBNativeAdsManagerDelegate实现方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1105002.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存