2015-09-04 59 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

相關問題