8

我想使用预建视图FBNativeAdView(不想自定义 FBNative 广告)。如链接中给出的

FBNativeAdView 创建预构建的原生广告模板视图并管理原生广告。

我确实更改了Facebook SDK中给出的NativeAdSample示例。并添加为 mainView(adUIView) 的子视图。FBNativeAdView

-(void) nativeAdDidLoad: (FBNativeAd * ) nativeAd 
{
        NSLog(@"Native ad was loaded, constructing native UI...");

        if (self._nativeAd) 
        {
            [self._nativeAd unregisterView];
        }

        self._nativeAd = nativeAd;

        // Here I did add
        FBNativeAdViewAttributes * attributes = [[FBNativeAdViewAttributes alloc] init];
        attributes.backgroundColor = [UIColor whiteColor];
        attributes.titleColor = [UIColor blackColor];

        FBNativeAdView * fbNativeAdView = [FBNativeAdView nativeAdViewWithNativeAd: self._nativeAd withType: FBNativeAdViewTypeGenericHeight300 withAttributes: attributes];
}

所以问题是如何添加fbNativeAdView为 ParentView 的子视图,以便它应该在父视图中查看。我做到了

[self.adUIView addSubview:fbNativeAdView];

没有成功。

原生广告模板提供了有关如何FBNativeAdViewFBNativeAd.但没有告诉如何FBNativeAdView在 uiview 中使用的信息。

4

2 回答 2

1

现在它使用添加框架FBNativeAdView作为

fbNativeAdView.frame = CGRectMake(0, 0, 320, 120);

现在原生广告模板也提供了有关如何FBNativeAdView在 uiview 中使用的信息。

可以通过更改其元素的值来自定义广告模板:

- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd 
{
  FBNativeAdViewAttributes *attributes = [[FBNativeAdViewAttributes alloc] init];

  attributes.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  attributes.buttonColor = [UIColor colorWithRed:0.4 green:0.9 blue:0.8 alpha:1];
  attributes.buttonTitleColor = [UIColor whiteColor];

  FBNativeAdView *adView = [FBNativeAdView nativeAdViewWithNativeAd:nativeAd 
      withType:FBNativeAdViewTypeGenericHeight300 withAttributes:attributes];

  [self.view addSubview:adView];

  CGSize size = self.view.bounds.size;
  CGFloat xOffset = size.width / 2 - 160;
  CGFloat yOffset = (size.height > size.width) ? 100 : 20;
  adView.frame = CGRectMake(xOffset, yOffset, 320, 300);

  // Register the native ad view and its view controller with the native ad instance
  [nativeAd registerViewForInteraction:adView withViewController:self];
}
于 2016-03-09T09:56:00.913 回答
-2

NativeAdView 使用 FBMediaView 创建广告。您的 nativeAdView 300 的高度太低,无法加载任何类型的 FBMediaView。

如果您想使用 300 百的高度,请创建一个原生视图 (iOS) 并使用 fbNativeAd 返回的属性。例如,在您的 nativeAdDidLoad 中执行此操作:

customView.titleLabel = nativeAd.title;
FFBAdImage *icon = nativeAd.icon;
[icon loadImageAsyncWithBlock:^(UIImage * _Nullable image) 
{
    [customView.imageView setImage:image]; //image returned by fb is 128x128
}];
customView.fbAdBtn.titleLabel.text = nativeAd.callToAction;

[self.view addSubView:customView];

如果您希望整个自定义视图都可以点击,那么到此

[nativeAd registerViewForInteraction:customView withViewController:self]; 

如果您希望仅通过自定义视图中的按钮执行操作,请执行此操作。

NSArray *clikAble = [NSArray alloc] initWithObjects:customView.fbAdBtn];
[nativeAd registerViewForInteraction:customView withViewController:self withClickableViews:clikAble];

您可以根据需要使用许多其他属性。

并且不要忘记遵循此准则:https ://developers.facebook.com/docs/audience-network/guidelines/native-ads

并尝试制作全屏尺寸的 FBNativeAdView,我认为这肯定会加载视图。

于 2015-11-16T12:28:34.987 回答