# Native Ads

To integrate Native Ads, ensure you have integrated the DT Exchange [IASDKCore Libraries](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/..#h_01h959gwafx2axgb4wwt1nxt6w). Configure the native ad spot, create an Ad Request, and then load the ad and map the assets to your native view components.

## Importing the SDK <a href="#h_01k8pcdpmzntc4v0k5941gfkna" id="h_01k8pcdpmzntc4v0k5941gfkna"></a>

Import the following `IASDKCore` module into your desired view controller:

{% code title="Objective-C" %}

```objective-c
#import <IASDKCore/IASDKCore.h>
```

{% endcode %}

## Creating the Ad Request Object <a href="#h_01k8pcdpmz6bq0t6cdv4qjkk8c" id="h_01k8pcdpmz6bq0t6cdv4qjkk8c"></a>

Initialize an `IAAdRequest` and provide the `spotID` and a timeout value:

{% code title="Objective-C" %}

```objective-c
IAAdRequest *adRequest =
[IAAdRequest build:^(id _Nonnull builder) {
    // Configure ad request if needed
	builder.spotID = @”NATIVE AD SPOT ID”;
	builder.timeout = 15;
}];
```

{% endcode %}

## Declaring Your View Controller <a href="#h_01k8pcdpmzbcymeacwq8eddzpa" id="h_01k8pcdpmzbcymeacwq8eddzpa"></a>

Declare that your view controller conforms to the `IANativeAdDelegate` Protocol:

{% code title="Objective-C" %}

```objective-c
@interface ViewController() <IANativeAdDelegate>
```

{% endcode %}

For more information, see [Unit Content Delegate Protocols](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/delegate-protocols#unit).

## Initializing the Placement <a href="#h_01k8pcdpmzptzyy65yv5gk8t2g" id="h_01k8pcdpmzptzyy65yv5gk8t2g"></a>

Initialize the `IANativeAdSpot` (placement) and pass your `adRequest` object:

{% code title="Objective-C" %}

```objective-c
nativeAdSpot = [IANativeAdSpot build:^(IANativeAdSpot *builder) {
  builder.adRequest = adRequest;
  builder.delegate = self;
  builder.userInfo = @{
    @"placementIdentifier" : parameters.thirdPartyAdPlacementIdentifier
  };  // Optional
}];
```

{% endcode %}

## Fetching the Ad <a href="#h_01k8pcdpmzhp20am4ztbqgsff3" id="h_01k8pcdpmzhp20am4ztbqgsff3"></a>

Native Ads are available only through SDK Bidding. In SDK Bidding, DT Exchange must first generate a token for the Mediation SDK to use when sending the request to server.

### Generating the Token <a href="#h_01k8pcdpmzyfpw6sbhx5hafbjm" id="h_01k8pcdpmzyfpw6sbhx5hafbjm"></a>

The token can be generated upon SDK initialization.

{% code title="Objective-C" %}

```objective-c
NSString *biddingToken = FMPBiddingManager.sharedInstance.biddingToken;
```

{% endcode %}

Return type: `NSString *`

If an error occurs, the returned value is `nil`.

### Loading the Ad <a href="#h_01k8pcdpmz13f2vv4dqx533bcg" id="h_01k8pcdpmz13f2vv4dqx533bcg"></a>

If DT Exchange wins the auction, load the ad with the `signaldata (adm)` that was received from the server:

{% code title="Objective-C" %}

```objective-c
__weak typeof(self) weakSelf = self;
[self.nativeAdSpot
    loadAdWithMarkup:bidResponse
      withCompletion:^(IANativeAdAssets *nativeAdAssets, NSError *error) {
        if (nativeAdAssets != nil) {
          NSString *title = nativeAdAssets.adTitle;
          NSString *adDescription = nativeAdAssets.adDescription;
          NSString *callToActionText = nativeAdAssets.callToActionText;
          UIView *appIcon = nativeAdAssets.appIcon;
          UIView *mediaView = nativeAdAssets.mediaView;
          NSString *advertiserName = nativeAdAssets.advertiserName;
          NSNumber *rating = nativeAdAssets.rating;
          NSNumber *mediaAspectRatio = nativeAdAssets.mediaAspectRatio;
        } else if (error != nil) {
          NSLog(@"Error: %@", error);
        }
      }];
```

{% endcode %}

For a complete list of Native Ads asset types, see the [oRTB Specfication for Native Ads](https://docs.digitalturbine.com/dt-exchange/advertisers/dt-exchange-openrtb-2.5-specs#object-native).

## Registering Views for Interaction <a href="#h_01k8pcdpmzj0617y2m92h6k3j7" id="h_01k8pcdpmzj0617y2m92h6k3j7"></a>

You must register the views that will respond to user interaction, such as clicks. It is recommended to use the provided ViewTag enumeration for mapping views.

{% code title="Objective-C" %}

```objective-c
@objc public enum ViewTag: Int {
    case title = 1
    case mediaView = 2 // both main image and video share this tag
    case icon = 4
    case description = 5
    case rating = 6
    case cta = 7
    case root = 8
}
```

{% endcode %}

After setting the tags on your views, register them with the ad assets:

{% code title="Objective-C" %}

```objective-c
container.tag = ViewTagRoot;
mediaViewHolder.tag = ViewTagMediaView;
iconHolder.tag = ViewTagIcon;
adTitle.tag = ViewTagTitle;
ratingLabel.tag = ViewTagLabel;
adDescription.tag = ViewTagDescription;
ctaButton.tag = ViewTagCta;

// Register Views for Interaction
[nativeAdAssets registerViewForInteraction:container
    mediaView:mediaViewHolder
    iconView:iconHolder
    clickableViews:@[
        adTitle,
        ratingLabel,
        adDescription,
        ctaButton
]];
```

{% endcode %}
