2015-09-04 108 views
8

我想用从FBNativeAdView预建视图(不希望自定义FBNative广告)在linkIOS Facebook添加FBNativeAdView作为子视图

的FBNativeAdView。至于给创建预置的原生广告模板的意见和 管理原生广告。

而且我也改变了NativeAdSample例如Facebook SDK给出。而添加FBNativeAdView为MAINVIEW(adUIView)的一个子视图。

-(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的子视图,所以应该查看父view.I做到了

[self.adUIView addSubview:fbNativeAdView]; 

没有成功。

Native Ad Template给出了有关如何从FBNativeAd得到FBNativeAdView的信息。但没有告知如何在uiview中使用FBNativeAdView

+0

“没有成功” - >发生了什么事?任何错误/通知? – Roemer

+0

只有白色的背景视图。 –

+0

我也一样...只是背景(我可以设置颜色),但没有其他内容。这些例子甚至没有使用FBNativeAdView – Marco

回答

0

现在工作使用FBNativeAdView作为

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

而且现在Native Ad Template提供了有关如何使用的UIView信息FBNativeAdView添加帧。

广告模板可以通过改变其 元素的值进行定制:

- (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]; 
} 
-2

NativeAdView使用FBMediaView创建广告。 nativeAdView 300的高度对任何一种FBMediaView来说都太低。

如果要使用300百个高度,请创建一个本机视图(iOS)并使用fbNativeAd返回的属性。例如如果你想,如果你想只通过按钮在您的自定义视图采取行动,那么这样做你的整个自定义视图可以点击然后这个

[nativeAd registerViewForInteraction:customView withViewController:self]; 

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]; 

:这样做在你的nativeAdDidLoad 。

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我认为肯定会加载一个视图。

+0

这是解决方案的家伙 - 你的nativeAdView 300的高度也是对任何类型的FBMediaView来说都是低的。 – Luda

+1

请等待,因为您说Facebook提供的默认值太低而无法使用,例如FBNativeAdViewTypeGenericHeight100,FBNativeAdViewTypeGenericHeight300 –

+0

@XCodeWarrier它们对于FBMediaView来说太低。 – ibnetariq