Lud*_*uda 13 ios swift facebook-audience-network
以下代码行构成了我的UI堆栈
adMediaView.nativeAd = nativeAd
// adMediaView - FBMediaView
// nativeAd - FBNativeAd
Run Code Online (Sandbox Code Playgroud)
我已经尝试将它放在后台线程异步执行它但它没有帮助.有办法解决吗?
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),{
adMediaView.nativeAd = nativeAd
});
Run Code Online (Sandbox Code Playgroud)
我已经FBAudienceNetwork
通过pod 安装并立即更新了它.我的最新版本是4.7.0
pod 'FBAudienceNetwork'
Run Code Online (Sandbox Code Playgroud)Piy*_*ush -1
NativeAdView
用于FBMediaView
创建广告。\n现在,在您的视图控制器头文件中声明 FBNativeAdDelegate 协议以及声明实例变量并将其连接到您的 UI .XIB:
@import FBAudienceNetwork; // import Audience Network module\n\n@interface MyViewController : UIViewController <FBNativeAdDelegate>\n // Other code might go here...\n @property (weak, nonatomic) IBOutlet UIImageView *adIconImageView;\n @property (weak, nonatomic) IBOutlet UILabel *adTitleLabel;\n @property (weak, nonatomic) IBOutlet UILabel *adBodyLabel;\n @property (weak, nonatomic) IBOutlet UIButton *adCallToActionButton;\n @property (weak, nonatomic) IBOutlet UILabel *adSocialContextLabel;\n @property (weak, nonatomic) IBOutlet UILabel *sponsoredLabel;\n\n @property (weak, nonatomic) FBMediaView *adCoverMediaView;\n\n @property (weak, nonatomic) IBOutlet UIView *adView;\n@end\n
Run Code Online (Sandbox Code Playgroud)\n\n然后,在视图控制器的实现文件中添加一个方法来初始化FBNativeAd
并请求加载广告:
FBNativeAd *nativeAd;\nFBAdchoicesView *adChoicesView;\n\n- (void)showNativeAd\n{\n nativeAd = [[FBNativeAd alloc] initWithPlacementID:@"YOUR_PLACEMENT_ID"];\n nativeAd.delegate = self;\n [nativeAd loadAd];\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n现在您已经添加了加载广告的代码,请添加以下函数来处理加载失败并在加载后构建广告:
\n\n- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd\n{\n [self.adTitleLabel setText:nativeAd.title];\n [self.adBodyLabel setText:nativeAd.body];\n [self.SocialContextLabel setText:nativeAd.socialContext];\n [self.sponsoredLabel setText:@\xe2\x80\x9dSponsored\xe2\x80\x9d];\n [self.adCallToActionButton setTitle:nativeAd.callToAction];\n\n [nativeAd.icon loadImageAsyncWithBlock:^(UIImage *image) {\n [self.adIconImageView setImage:image]; \n }];\n\n // Allocate a FBMediaView to contain the cover image or native video asset\n adCoverMediaView = [[FBMediaView alloc] initWithFrame:coverFrame]];\n [adCoverMediaView setNativeAd:nativeAd];\n\n // Add adChoicesView\n adChoicesView = [[FBAdChoicesView alloc] initWithNativeAd:nativeAd];\n [adView addSubview:adChoicesView];\n [adChoicesView updateFrameFromSuperview];\n\n // Register the native ad view and its view controller with the native ad instance\n [nativeAd registerViewForInteraction:adView withViewController:self];\n}\n\n- (void)nativeAd:(FBNativeAd *)nativeAd didFailWithError:(NSError *)error\n{\n NSLog(@"Ad failed to load with error: %@", error);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n要显示原生广告封面图像,建议使用 Facebook Audience Network MediaView,它可以同时显示图像和视频资源。
\n\n参考:https://developers.facebook.com/docs/audience-network/ios/native-api
\n 归档时间: |
|
查看次数: |
1713 次 |
最近记录: |