Concept

The native ads allow you to get the metadata of the campaigns for a smoother integration in your application. It's very similar to our in-stream ads (sashimi), but without the views stuff.
The list of the available properties is available in the header of the AFNativeAd class.
You can check the API reference for a more friendly interface.

Get a Native Ad

Before anything make sure your walked through these required steps before starting the integration of the Native Ads.

Imports

The first thing you need to do is to import the required classes:

// Required for Appsfire advertising.
#import "AppsfireAdSDK.h"

// The Native Ad header file
#import "AFNativeAd.h"

Calculate how many ads are available

Before getting any Native Ad, you need to check how many ads are available:

NSUInteger nativeAdsCount = [AppsfireAdSDK numberOfNativeAdsAvailable:@"ZONE_ID"];

if (nativeAdsCount > 0) {

    // Get a native ad

}

ZONE_ID is the zone ID for your Native ads as provided by Appsfire.

During the initialization of the library, this method will return 0 because we didn't download the ads from our web-service. You can solve this problem by using the following method that will help you differenciate the state "pending" from the state "no ad".

AFAdSDKAdAvailability nativeAdStatus = [AppsfireAdSDK isThereNativeAdAvailable];

if (nativeAdStatus == AFAdSDKAdAvailabilityYes) {

    // Get a native ad

}

else if (nativeAdStatus == AFAdSDKAdAvailabilityPending) {

    // Retry later

}

Get a native ad

When the returned count is not 0 then you know you can get a native ad object.

NSError *error;
AFNativeAd *afNativeAd;

// Get the native ad
afNativeAd = [AppsfireAdSDK nativeAdWithError:&error forZone:@"ZONE_ID"];

// Before using this ad make sure that the returned object is not `nil` and that there is no error.
if (afNativeAd != nil && error == nil) {

    // You can safely use the ad

}

You are now ready to display the metadata of the native ad inside your own view. You can find an example in our demo projects!

Connect the native ad with your view

As for our in-stream ads (sashimi), we take care of detecting and managing the impression and the click. You must bind the native ad object with the view that will display the information.

AFNativeAd *afNativeAd;
UIView *nativeAdView;

// [...]

// Connect the native ad with the view
[afNativeAd connectViewForDisplay:nativeAdView withClickableViews:nil];

By default we assume that the displayed zone should be entirely clickable. But you can target some specific views if it shouldn't be the case.

And when you are finished, please disconnect:

AFNativeAd *afNativeAd;

// [...]

// Disconnect the native ad from the view
[afNativeAd disconnectViewForDisplay];

Use the delegate

A delegate method let you know once some ads are available.
We recommend you to use it for a ideal implementation.

Don't forget to set the delegate via [AppsfireAdSDK setDelegate:object]

- (void)nativeAdsRefreshedAndAvailable {

    NSLog(@"Native ads were received");

    // check how many native ads are available
    NSUInteger nativeAdsCount = [AppsfireAdSDK numberOfNativeAdsAvailable];
    NSLog(@"Number of native ads received:%lu", (unsigned long)nativeAdsCount);

}
For a complete example of integration, refer to the demo project dedicated to the native ads.
You can find it in the Xcode package of our SDK in examples/ folder.

Third-party network

For now we only created an adapter for MoPub. Please check the documentation on github to learn how to use it within your application.