Show Native Ads on iOS

Native ads give you the ability to create ads that are customized to match the look and feel of the rest of your application. This page describes our Native Ads API at a high level, and includes a usage example. For a complete reference, see the inline documentation in the code.

Native networks supported through mediation:

Maintain references to request and response objects!

You must maintain a reference to the ANNativeAdRequest and ANNativeAdResponse objects you create. Otherwise they will go out of scope and cause unexpected behavior.

In order to serve native ads, you will send a "native ad request" and receive a "native ad response". In the example request and response below, we:

Request

First, we set up the request object and set some of its properties such as the placement ID and whether to pre-load the ad's icon image:

ANNativeAdRequest *request = [[ANNativeAdRequest alloc] init];
request.placementId = @"123456";
request.rendererId = 123;
request.gender = ANGenderMale;
request.shouldLoadIconImage = YES;
request.shouldLoadMainImage = YES;
request.delegate = self;
[request loadAd];

Response

Assuming the request is successful, we load the native ad assets from the response into the view and register it so that we can track user interactions such as clicks:

- (void)adRequest:(ANNativeAdRequest *)request didReceiveResponse:(ANNativeAdResponse *)response {
      // (code which loads the view)
      MyDummyView *view;
      view.title.text = response.title;
      view.text.text = response.body;
      view.iconImageView.image = response.iconImage;
      view.mainImageView.image = response.mainImage;
      [view.callToActionButton setTitle:response.callToAction forState:UIControlStateNormal];
 
      response.delegate = self;
 
      [response registerViewForTracking:view
                 withRootViewController:self
                         clickableViews:@[view.callToActionButton, view.mainImageView]
                                  error:nil];

 		[response unregisterViewFromTracking];
 }

In this example response, we use several elements of a native ad:

List of Fields Supported in Native

As if version 5.0 of the Mobile SDK, support for native assets is aligned with how native creatives are set up on Console.

If you are still using Legacy Native in Console, you will need to move to "New" Native for your creatives.

The following is a comprehensive list of native assets supported in the SDKs.

AssetSupported Pre 5.0?Supported Post 5.0?v5.0+ API-Usage Example
Image, Width, HeightYes, Yes, YesYes, Yes, Yes
response.mainImage;
response.mainImageSize;
response.mainImageURL;
Icon+Width+HeightYes, No, NoYes, Yes, Yes
response.iconImage;
response.iconImageURL;
response.iconImageSize;
TitleYesYes
response.title;
Sponsored byYesYes
response.sponsoredBy;
Body textYesYes
response.body;
Desc2YesYes
response.additionalDescription;
Call-to-actionYesYes
response.callToAction;
Rating, ScaleYes, YesYes, No
response.rating;
LikesNoYes (json only)
NSDictionary *customElements = response.customElements[@"ELEMENT"];
 
if(customElements){
  NSString *likes =  customElements[@"likes"]
NSString *downloads = customElements[@"downloads"]
NSString *price = customElements[@"price"]
NSString *saleprice = customElements[@"saleprice"]
NSString *phone = customElements[@"phone"]
NSString *address = customElements[@"address"];
NSString *displayurl =  customElements[@"displayurl"]
}
DownloadsNoYes (json only)
PriceNoYes (json only)
Sale PriceNoYes (json only)
PhoneNoYes (json only)
AddressNoYes (json only)
Display URLNoYes (json only)
Privacy URLNoYes
response.privacyLink;
VideoNoYes
response.vastXML;
CustomYesNo 
ContextYesNo 
Full textYesNo 

Related Topics