< font-size: 16px;"> < font-size: 16px;">编程之家收集整理的这篇文章主要介绍了ios–FBAudienceNetwork:将FBNativeAd设置为FBMediaView堆叠UI,编程之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。 < font-size: 16px;">以下代码行使我的UI堆栈 < font-size: 16px;">adMediaView.nativeAd = nativeAd < font-size: 16px;">// adMediaView - FBMediaView < font-size: 16px;">// nativeAd - FBNativeAd
< font-size: 16px;">我已经尝试将其在后台线程中异步执行,但没有帮助.有办法解决吗? < font-size: 16px;">dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT,0),{ < font-size: 16px;"> adMediaView.nativeAd = nativeAd < font-size: 16px;">});
< font-size: 16px;">我已经通过pod安装了FBAudienceNetwork,并且更新了它.最新版本是4.7.0 < font-size: 16px;">pod 'FBAudienceNetwork'
< font-size: 16px;">解决方法
< font-size: 16px;">NativeAdView使用FBMediaView创建广告.
< font-size: 16px;">现在,在您的View Controller头文件中声明了FBNativeAdDelegate协议,并声明并将实例变量连接到您的UI.XIB: < font-size: 16px;">@import FBAudienceNetwork; // import Audience Network module < font-size: 16px;">@interface MyViewController : UIViewController <FBNativeAdDelegate> < font-size: 16px;"> // Other code might go here... < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UIImageView *adIconImageView; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UILabel *adTitleLabel; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UILabel *adBodyLabel; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UIButton *adCallToActionButton; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UILabel *adSocialContextLabel; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UILabel *sponsoredLabel; < font-size: 16px;"> @property (weak,nonatomic) FBMediaView *adCoverMediaView; < font-size: 16px;"> @property (weak,nonatomic) IBOutlet UIView *adView; < font-size: 16px;">@end
< font-size: 16px;">然后,在View Controller的实现文件中添加一个初始化FBNativeAd并请求加载广告的方法: < font-size: 16px;">FBNativeAd *nativeAd; < font-size: 16px;">FBAdchoicesView *adChoicesVie怎样电商运营商w; < font-size: 16px;">- (void)showNativeAd < font-size: 16px;">{ < font-size: 16px;"> nativeAd = [[FBNativeAd alloc] initWithPlacementID:@"YOUR_PLACEMENT_ID"]; < font-size: 16px;"> nativeAd.delegate = self; < font-size: 16px;"> [nativeAd loadAd]; < font-size: 16px;">}
< font-size: 16px;">现在,您已经添加了加载广告的代码,添加以下功能来处理加载故障,并在加载后构建广告: < font-size: 16px;">- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd < font-size: 16px;">{ < font-size: 16px;"> [self.adTitleLabel setText:nativeAd.title]; < font-size: 16px;"> [self.adBodyLabel setText:nativeAd.body]; < font-size: 16px;"> [self.SocialContextLabel setText:nativeAd.socialContext]; < font-size: 16px;"> [self.sponsoredLabel setText:@”Sponsored”]; < font-size: 16px;"> [self.adCallToActionButton setTitle:nativeAd.callToAction]; < font-size: 16px;"> [nativeAd.icon loadImageAsyncWithBlock:^(UIImage *image) { < font-size: 16px;"> [self.adIconImageView setImage:image]; < font-size: 16px;"> }]; < font-size: 16px;"> // Allocate a FBMediaView to contain the cover image or native video asset < font-size: 16px;"> adCoverMediaView = [[FBMediaView alloc] initWithFrame:coverFrame]]; < font-size: 16px;"> [adCoverMediaView setNativeAd:nativeAd]; < font-size: 16px;"> // Add adChoicesView < font-size: 16px;"> adChoicesView = [[FBAdChoicesView alloc] initWithNativeAd:nativeAd]; < font-size: 16px;"> [adView addSubview:adChoicesView]; < font-size: 16px;"> [adChoicesView updateFrameFromSuperview]; < font-size: 16px;"> // Register the native ad view and its view controller with the native ad instance < font-size: 16px;"> [nativeAd registerViewForInteraction:adView withViewController:self]; < font-size: 16px;">} < font-size: 16px;">- (void)nativeAd:(FBNativeAd *)nativeAd didFailWithError:(NSError *)error < font-size: 16px;">{ < font-size: 16px;"> NSLog(@"Ad failed to load with error: %@",error); < font-size: 16px;">}
< font-size: 16px;">要显示原生广告封面图淘宝短视频转化片,建议您使用能够同时显示图片和影片资源的Facebook Audience Network MediaView.
< font-size: 16px;">参考:https://developers.facebook.com/docs/audience-network/ios/native-api < font-size: 16px;">总结 < font-size: 16px;">以上是编程之家为你收集整理的ios–FBAudienceNetwork:将FBNativeAd设置为FBMediaView堆叠UI全部内容,希望文章能够帮你解决ios–FBAudienceNetwork:将FBNativeAd设置为FBMediaView堆叠UI所遇到的程序开发问题。 < font-size: 16px;">如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
|