ios Facebook add FBNativeAdView as Subview

空扰寡人 提交于 2019-12-04 03:27:51

Now It work using add frame in FBNativeAdView as

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

Also now Native Ad Template gives information about how to use FBNativeAdView in uiview.

The ad template can be customized by changing the values of its elements:

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

NativeAdView uses FBMediaView for creating an ad. Your hight for nativeAdView 300, is too low for any kind of FBMediaView to load.

If you want to use hight of 300 hundred, create a native view(iOS) and use properties returned by fbNativeAd. e.g. do this in your 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];

if you want your whole custom view to be clickable then to this

[nativeAd registerViewForInteraction:customView withViewController:self]; 

if you want action to be taken only by button in your custom view then do this.

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

There are number of other properties you can use according to your need.

And don't forget to follow this guidelines : https://developers.facebook.com/docs/audience-network/guidelines/native-ads

And try to make full screen size FBNativeAdView i think that will definitely load a view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!