# Interstitial Ads

To integrate Interstitial ads, ensure you have integrated the [IASDKCore Libraries](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/..#h_01h959gwafx2axgb4wwt1nxt6w). Configure the ad placement and its controllers, create an Ad Request, and then fetch and display the ad.

## Importing the SDK <a href="#id-01k5e4za1fjbra57dkvd5hgkn5" id="id-01k5e4za1fjbra57dkvd5hgkn5"></a>

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

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

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

{% endcode %}

## Adding Properties <a href="#h_01k5nq87hrbb4qmhbkzntm241m" id="h_01k5nq87hrbb4qmhbkzntm241m"></a>

Retain each `IASDK` module on the client side, and declare properties for:

* `adSpot` (placement)
* `UnitController`
* `videoContentController`&#x20;
* `mraidConentController`

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

```objective-c
@property (nonatomic, strong) IAAdSpot *adSpot;
@property (nonatomic, strong) IAFullscreenUnitController *unitController;
@property (nonatomic, strong) IAVideoContentController *videoContentController;
@property (nonatomic, strong) IAMRAIDContentController *mraidContentController;
```

{% endcode %}

Optionally, create an `IAUserData` object for better ad targeting:

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

```objective-c
IAUserData *userData =
[IAUserData build:^(id  _Nonnull builder) { 
    builder.age = 34;     
    builder.gender = IAUserGenderTypeMale;    
    builder.zipCode = @"90210";
}];
IASDKCore.sharedInstance.userData = userData;
```

{% endcode %}

{% hint style="info" %}
The `build:` method is synchronous and runs on the same thread that it is invoked from, similar to iOS's `enumerateObjectsUsingBlock`. As a result, memory management like `weak` references are not needed inside the block.
{% endhint %}

Set global variables for SDK bidding provided in `IASDKCore` shared instance:

* `userData`
* `muteAudio`
* `mediationType`
* `debugger`

#### Example:

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

```objective-c
IASDKCore.sharedInstance.userData = userData;
IASDKCore.sharedInstance.muteAudio = YES;
IASDKCore.sharedInstance.mediationType = IAMediationMax.new;
IASDKCore.sharedInstance.debugger = [IADebugger build:^(id  _Nonnull builder) {
        builder.server = @"wv.inner-active";
        builder.mockResponsePath = @"bannerresponseforci";
        builder.database = @"4321";
    }];
  
```

{% endcode %}

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

{% hint style="info" %}
This step is not mandatory for SDK Bidding mediation.
{% endhint %}

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

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

```objective-c
AAdRequest *adRequest =
[IAAdRequest build:^(id  _Nonnull builder) { 
    builder.spotID = @"YOUR Interstitial_SPOT ID";    
    builder.timeout = 5;    
}];
```

{% endcode %}

Optionally, you can opt to mute non-rewarded interstitial ads by adding:

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

```objective-c
//You can also call the mute through the static object
//In both cases, the result is the same:
IASDKCore.sharedInstance().muteAudio = YES
```

{% endcode %}

## Initializing the Video Content Controller <a href="#h_01k5nq8kpw61g32a9dp8ys7swv" id="h_01k5nq8kpw61g32a9dp8ys7swv"></a>

Initialize the `videoContentController`:

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

```objective-c
IAVideoContentController *videoContentController =
    [IAVideoContentController build:
     ^(id  _Nonnull builder) {
        builder.videoContentDelegate = self; 
        // A delegate should be passed in order to get video content related callbacks;
}];
    
self.videoContentController = videoContentController; 
// The Video Content ControllerPage should be retained by a client side;
```

{% endcode %}

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

Declare your view controller conforms to the `IAVideoContentDelegate` protocol:

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

```objective-c
@interface YourViewController ()< IAVideoContentDelegate>
```

{% endcode %}

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

## Initializing the MRAID Content Controller <a href="#h_01k5nqmgg6ez3s123kx9myrht5" id="h_01k5nqmgg6ez3s123kx9myrht5"></a>

Initialize the `IAMRAIDContentController`:

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

```objective-c
IAMRAIDContentController *mraidContentController =
    [IAMRAIDContentController build:
     ^(id  _Nonnull builder) {
        builder.MRAIDContentDelegate = self;
// a delegate should be passed in order to get video content related callbacks;
}];

self.mraidContentController = mraidContentController; 
// the MRAID Content ControllerPage should be retained by a client side;
```

{% endcode %}

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

Declare your view controller conforms to the `IAMRAIDContentDelegate` Protocol:

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

```objective-c
@interface YourViewController () <IAVideoContentDelegate, IAMRAIDContentDelegate>
```

{% endcode %}

For more information, see [HTML/MRAID Delegate Protocols](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/delegate-protocols#html-mraid).

## Initializing the Full-Screen Unit Controller <a href="#h_01k5nqmvcvdqjc0209tfq6ermb" id="h_01k5nqmvcvdqjc0209tfq6ermb"></a>

Initialize the `IAFullscreenUnitController`:

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

```objective-c
IAFullscreenUnitController *fullscreenUnitController =
    [IAFullscreenUnitController build:^(id _Nonnull builder) {
      builder.unitDelegate = self;
      // all the needed content controllers should be added to the desired unit
      // controller:
      [builder addSupportedContentController:self.videoContentController];
      [builder addSupportedContentController:self.mraidContentController];
    }];

self.unitController = fullscreenUnitController;
// the Fullscreen Unit Controller should be retained by a client side;
```

{% endcode %}

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

Declare your view controller conforms to `IAUnitDelegate` Protocol:

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

```objective-c
@interface YourViewController () <IAVideoContentDelegate,
                                  IAMRAIDContentDelegate,
                                  IAUnitDelegate>
```

{% 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_01k5nqn6ny62swjegsdyyxa6fa" id="h_01k5nqn6ny62swjegsdyyxa6fa"></a>

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

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

```objective-c
IAAdSpot *adSpot = [IAAdSpot build:^(id  _Nonnull builder) {
        builder.adRequest = adRequest; 
// pass here the ad request object;
        [builder addSupportedUnitController:self.unitController];
}];

self.adSpot = adSpot; 
// The Ad Spot should be retained by a client side;
```

{% endcode %}

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

The way in which the ad is fetched depends on the mediation type — Waterfall or SDK Bidding.

### Fetching the Ad for Waterfall <a href="#h_01k7y23wvdkbt0kr40nhdhahdg" id="h_01k7y23wvdkbt0kr40nhdhahdg"></a>

In Waterfall mediation, use `fetchAdWithCompletion:` and `showAdAnimated:` to fetch the ad:

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

```objective-c
// Declare a weak var, because of a retained block:
__weak typeof(self) weakSelf = self;
    
[self.adSpot fetchAdWithCompletion:^(IAAdSpot * _Nullable adSpot, IAAdModel * _Nullable adModel, NSError * _Nullable error) {
        if (!error) {
            [weakSelf.unitController showAdAnimated:YES completion:nil];
        }
}];
```

{% endcode %}

### Fetching the Ad for SDK Bidding <a href="#h_01k7y23wvd3maetdg0yjab35gn" id="h_01k7y23wvd3maetdg0yjab35gn"></a>

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**

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**

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
[self.adSpot
    loadAdWithMarkup:adm
      withCompletion:^(IAAdSpot *_Nullable adSpot, IAAdModel *_Nullable adModel,
                       NSError *_Nullable error) {
        if (error) {
          NSLog(@"Failed to get an ad: %@\n", error);
        } else {
          // If is in-view ad unit response, show in view:
          if (adSpot.activeUnitController == weakSelf.viewUnitController) {
            [weakSelf.viewUnitController showAdInParentView:weakSelf.view];
          }
          // If is fullscreen ad unit response, show as fullscreen:
          else if (adSpot.activeUnitController == weakSelf.fsUnitController) {
            [weakSelf.fsUnitController showAdAnimated:YES completion:nil];
          }
        }
      }];
```

{% endcode %}

<br>
