# All-in-One

To integrate all ad types in one integration, 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="#h_01k56dapegbkdgykkckdvbcw50" id="h_01k56dapegbkdgykkckdvbcw50"></a>

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

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

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

{% endcode %}

## Creating Properties <a href="#h_01k56dapegvk17480qy3maw1bq" id="h_01k56dapegvk17480qy3maw1bq"></a>

Create properties for all types of controllers and content controllers:

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

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

{% endcode %}

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 User Data Object <a href="#h_01k56dapegj86hzy4bdx8t8ctz" id="h_01k56dapegj86hzy4bdx8t8ctz"></a>

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, special memory management like `weak` references are not needed inside the block.
{% endhint %}

## Initializing the Ad Request Object <a href="#h_01k56dapeg996dhygwr74btvrt" id="h_01k56dapeg996dhygwr74btvrt"></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 Controller <a href="#h_01k56dapegqsc1s59rdw68wxhz" id="h_01k56dapegqsc1s59rdw68wxhz"></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_01k56dapeghgmzbsybmxr5w62q" id="h_01k56dapeghgmzbsybmxr5w62q"></a>

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

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

```
@interface YourViewController () <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 Video Content Controller <a href="#h_01k56dapegyf523qrgncfcvqqj" id="h_01k56dapegyf523qrgncfcvqqj"></a>

Initialize the `IAMVideoContentController`:

{% 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_01k56dapehc0vq4c3qwbvk3a8h" id="h_01k56dapehc0vq4c3qwbvk3a8h"></a>

Declare that the video content controller conforms to the `IAVideoContentDelegate` protocol:

**Objective-C**

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

```objective-c
@interface YourViewController  () <IAMRAIDContentDelegate, 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 View Unit Controller <a href="#h_01k56dapehet17g0qskrcdm82e" id="h_01k56dapehet17g0qskrcdm82e"></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.videoContentController];
      [builder addSupportedContentController:self.mraidContentController];
    }];
self.viewUnitController = viewUnitController;
// the View Unit Controller should be retained by a client side;
```

{% endcode %}

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

Initialize the `IAFullscreenUnitController`:

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

```objective-c
IAFullscreenUnitController *fullscreenUnitController =
    [IAFullscreenUnitController build:^(id _Nonnull builder) {
      builder.unitDelegate = self;
      // All the required 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 the View Unit Controller and the Full Screen Unit Controller <a href="#h_01k5ebbgegyyvv4zr7qxevrcvw" id="h_01k5ebbgegyyvv4zr7qxevrcvw"></a>

Declare that the video content controller and full screen unit conform to the `IAVideoContentDelegate` protocol:

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

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

{% 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_01k5ebbgegc29m63h08dhjym8j" id="h_01k5ebbgegc29m63h08dhjym8j"></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;
  // All the supported (by a client side) unit controllers:
  [builder addSupportedUnitController:self.viewUnitController];
  [builder addSupportedUnitController:self.fsUnitController];
}];
self.adSpot = adSpot;
// The Ad Spot should be retained by a client side
```

{% endcode %}

## Fetching the Ad <a href="#h_01k56dapeh9754tarw5170eny4" id="h_01k56dapeh9754tarw5170eny4"></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_01k7y38g3djtb7gdacp8751h9e" id="h_01k7y38g3djtb7gdacp8751h9e"></a>

In Waterfall mediation, use `fetchAdWithCompletion:` and `showAdAnimated:completion` 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 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 %}

### Fetching the Ad for SDK Bidding <a href="#h_01k7y38g3dxeg4ja12e8ec062c" id="h_01k7y38g3dxeg4ja12e8ec062c"></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 %}
