What is Native Ads Manager?

The Native Ads Manager is designed to help you load and show multiple ads in a single slot within a content feed in your app. For example, if your app shows a feed of news articles, you can use Native Ads Manager to show multiple ads in place of a single article, and let the user scroll horizontally through those ads.

Native Ads Manager with Table View Controller

Let's implement a horizontal scroll view controller that uses the native ad manager to present a list of ads as follows:

Step 1: Use NativeAdManager to Request Ads

Step 2: Use NativeAdManager to Show Ads

Step 1: Use NativeAdManager to Request Ads

  1. In your View Controller header file, import the SDK header, declare that ViewController implements the FBNativeAdDelegate and FBNativeAdsManagerDelegate protocols.

    In addition, add following properties to View Controller interface.
    @property (nonatomic, strong) FBNativeAdsManager *adManager;
    @property (nonatomic, strong) FBNativeAdScrollView *scrollView;
  2. In viewDidLoad method, add the following lines of code:
    FBNativeAdsManager *adManager = [[FBNativeAdsManager alloc] initWithPlacementID:@"YOUR_PLACEMENT_ID" forNumAdsRequested:5];
    adManager.delegate = self; 
    adManager.mediaCachePolicy = FBNativeAdsCachePolicyAll;
    [adManager loadAds];
    self.adManager = adManager;
    When initializing and creating adManager, replace YOUR_PLACEMENT_ID with your own placement id string. If you don't have a placement id or don't know how to get one, you can refer to the Getting Started Guide.

    Set mediaCachePolicy to be FBNativeAdsCachePolicyAll. This will configure the native ad to wait to be called in nativeAdDidLoad method until all ad assets are loaded.

    Audience Network supports five cache options in native ads as defined in the FBNativeAd.h:
    Cache Constants Description


    No pre-caching, default


    Pre-cache ad icon


    Pre-cache ad images


    Pre-cache ad video


    Pre-cache all (icon, images, and video)

    You need to call [self.adManager loadAds]; to load ad.

  3. You need to implement nativeAdsLoaded and nativeAdsFailedToLoadWithError to check if ads are loaded successfully by the adsManager as follows:
    #pragma mark FBNativeAdsManagerDelegate implementation
    - (void)nativeAdsLoaded 
        NSLog(@"Native ad was loaded, constructing native UI...");
    - (void)nativeAdsFailedToLoadWithError:(NSError *)error 
        NSLog(@"Native ad failed to load with error: %@", error);
    Build and run the app. You should see the log message "Native ad was loaded" if ads are loaded successfully.

Step 3: Use NativeAdManager to Show Ads

In this step, you will learn how to use FBNativeAdScrollView to display ads that can be scrolled horizontally.

  1. In nativeAdsLoaded method, add the following lines of code.
    FBNativeAdScrollView *scrollView = [[FBNativeAdScrollView alloc] initWithNativeAdsManager:self.adManager withType:FBNativeAdViewTypeGenericHeight300];
    scrollView.delegate = self;
    scrollView.frame = CGRectMake(0, (self.view.bounds.size.height - 300.0)/2.0, self.view.bounds.size.width, 300.0);
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    FBNativeAdScrollView is used along with NativeAdManager to show ads horizontally. It has a FBNativeAdDelegate delegate property to be set to the view controller so that the controller will be notified when an ad is logged for click and impression.

  2. To be notified when an ad is clicked or seen by a user, you will need to implement the following methods in the controller class.
    - (void)nativeAdDidClick:(FBNativeAd *)nativeAd
        NSLog(@"Native ad was clicked.");
    - (void)nativeAdDidFinishHandlingClick:(FBNativeAd *)nativeAd
        NSLog(@"Native ad did finish click handling.");
    - (void)nativeAdWillLogImpression:(FBNativeAd *)nativeAd
        NSLog(@"Native ad impression is being captured.");
  3. Choose your build target to be device and run the above code, you should see something like this:

When running in the simulator, you need to set test mode to view test ads. Please refer to How to Use Test Mode for more information.

Next Steps

  • Submit your app for review.

  • As soon as we receive a request for an ad from your app or website, we'll review it to make sure it complies with Audience Network policies and the Facebook community standards. Learn more about our review process.

  • Explore our code samples which demonstrate how to use native ads. The NativeAdSample is available as part of the SDK and can be found under the FBAudienceNetwork/samples folder. Open the project with Xcode and run it either on a device or the simulator.

When using latest Xcode with Facebook Audience Network samples, Xcode will give signing error that the app id used in the sample app cannot be registered to your development team. You would need to change your bundle identifier to a unique string and try again.