Facebook Native Ads FBNativeAdsManagerDelegate实现方法未调用 [英] Facebook Native Ads FBNativeAdsManagerDelegate implementation methods did not called
问题描述
FBNativeAdsManagerDelegate
在Facebook本地广告在 UIViewController
类中正常工作,但在自定义NSObject类中使用时,它不工作其委托方法 nativeAdsLoaded
和 nativeAdsFailedToLoadWithError
未被调用。
FBNativeAdsManagerDelegate
in Facebook Native Ads working properly in UIViewController
class but when used in custom NSObject class its not working i.e. its delegate methods nativeAdsLoaded
and nativeAdsFailedToLoadWithError
did not get called.
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 的委托设为
As stated in above code I did set FBNativeAdsManager's delegate in requestNativeAd
method as
manager.delegate = self;
还用作 FBNativeAdsManagerDelegate,FBNativeAdDelegate
@interface CustomFBAd ()<FBNativeAdsManagerDelegate,FBNativeAdDelegate>
并将此代码称为
CustomFBAd *objFBAd = [[CustomFBAd alloc]init];
objFBAd.delegate = self;
[objFBAd requestNativeAd:@"my_FB_placement_Id"];
任何线索(注意:如果我在 UIViewController
)?感谢
any clue (Note : same code works if I use it in UIViewController
)? Thanks
推荐答案
如果您的委托方法在uiviewcontroller中调用,而不是代码有问题。我想你必须在控制器中有一个很好的CustomFBAd参考。因为没有其他参考文件占用您的CustomFBAd。希望它有助于
if your delegate methods are called in uiviewcontroller, than there is a problem with the code. I guess you have to have a strong reference of CustomFBAd in your controller. Because none of other references are taking hold of your CustomFBAd. hope it helps
这篇关于Facebook Native Ads FBNativeAdsManagerDelegate实现方法未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!