> For the complete documentation index, see [llms.txt](https://docs.digitalturbine.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalturbine.com/dt-exchange/sdk-configuration/integrating-the-ios-sdk/ios-ad-formats/banner-mrec-ads.md).

# Banner/MREC Ads

To integrate Banner/MREC ads, ensure you have integrated the [IASDKCore Libraries](/dt-exchange/sdk-configuration/integrating-the-ios-sdk.md#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-01h8e3fqsmwn10s7y43akm1pdm" id="id-01h8e3fqsmwn10s7y43akm1pdm"></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="#id-01h8e3fqsnp2bazspsrf4n0047" id="id-01h8e3fqsnp2bazspsrf4n0047"></a>

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

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

```objective-c
@property (nonatomic, strong) IAAdSpot *adSpot;
@property (nonatomic, strong) IAViewUnitController*viewUnitController;
@property (nonatomic, strong) IAMRAIDContentController*mraidContentController;
```

{% endcode %}

Optionally, create the `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="#id-01h89m2e9jyr2t7srjqetzchqy" id="id-01h89m2e9jyr2t7srjqetzchqy"></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
IAAdRequest *adRequest =
[IAAdRequest build:^(id  _Nonnull builder) { 
    builder.spotID = @"YOUR SPOT ID";    
    builder.timeout = 10; 
}];
```

{% endcode %}

## Initializing the MRAID Content Controller <a href="#id-01h8e3vmc7tps9j55yfk8ta180" id="id-01h8e3vmc7tps9j55yfk8ta180"></a>

Initialize the `IAMRAIDContentController`:

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

```objective-c
IAMRAIDContentController *mraidContentController =
[IAMRAIDContentController build: ^(id<IAMRAIDContentControllerBuilderh>  _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="#id-01h89dgv9f5wd3z51wsggjyag7" id="id-01h89dgv9f5wd3z51wsggjyag7"></a>

Declare that your view controller conforms to the `IAMRAIDContentDelegate` protocol:

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

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

{% endcode %}

For more information, see [HTML/MRAID Delegate Protocols](/dt-exchange/sdk-configuration/integrating-the-ios-sdk/delegate-protocols.md#html-mraid).

## Initializing the View Unit Controller <a href="#id-01h8e4r05n1c0f9ae2zrreewfc" id="id-01h8e4r05n1c0f9ae2zrreewfc"></a>

Initialize the `IAViewUnitController`:

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

```objective-c
IAViewUnitController *viewUnitController = [IAViewUnitController
    build:^(id<IAViewUnitControllerBuilder> _Nonnull builder) {
      builder.unitDelegate = self;
      // all the required content controllers should be added to the desired
      // unit controller:
      [builder addSupportedContentController:self.mraidContentController];
    }];

self.viewUnitController = viewUnitController;
// the View Unit Controller should be retained by a client side;
```

{% endcode %}

## Declaring Your View Controller <a href="#id-01h8e4d3128zwwmex23d9p51t1" id="id-01h8e4d3128zwwmex23d9p51t1"></a>

Declare that your view controller conforms to the `IAUnitDelegate` protocol:

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

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

{% endcode %}

For more information, see [Unit Content Delegate Protocols](/dt-exchange/sdk-configuration/integrating-the-ios-sdk/delegate-protocols.md#unit).

## Initializing the Placement <a href="#id-01h89dgv9fvtnan2petmwenpmq" id="id-01h89dgv9fvtnan2petmwenpmq"></a>

Initialize the `IAAdSpot` and pass your `adRequest` object:

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

```objective-c
IAAdSpot *adSpot = [IAAdSpot build:^(id<IAAdSpotBuilder>  _Nonnull builder) {
    builder.adRequest = adRequest; 
    // pass here the ad request object;    
    // all the supported (by a client side) unit controllers,
    // (in this case - view unit controller) should be added to the desired ad spot:     
    [builder addSupportedUnitController:self.viewUnitController];
}];

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

{% endcode %}

## Fetching the Ad <a href="#id-01h89dgv9fmy9zfr2v60evr0ch" id="id-01h89dgv9fmy9zfr2v60evr0ch"></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_01k7xyfzm4wa9xg8pcqw01qpax" id="h_01k7xyfzm4wa9xg8pcqw01qpax"></a>

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

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

```objective-c
// declare a weak property, because of block:
__weak typeof(self) weakSelf = self;

[self.adSpot fetchAdWithCompletion:^(IAAdSpot* _Nullable adSpot,
                                     IAAdModel* _Nullable adModel,
                                     NSError* _Nullable error) {
  if (error) {
    NSLog(@"Failed to get an ad: %@\n", error);
  } else {
    if (adSpot.activeUnitController == weakSelf.viewUnitController) {
      [weakSelf.viewUnitController showAdInParentView:weakSelf.view];
    }
  }
}];
```

{% endcode %}

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

In SDK Bidding, DT Exchange must first generate a token for the Mediation SDK to use when sending the request to the 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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digitalturbine.com/dt-exchange/sdk-configuration/integrating-the-ios-sdk/ios-ad-formats/banner-mrec-ads.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
