Integrating All-in-One

Introduction

This article describes how to support all non-native ads types and content in one integration. 

Init and Fetch

Note

Before continuing, please ensure you have integrated the IASDKCore and IASDKVideo modules here.

  1. Import all the IASDK modules into your desired view controller:

Importing All Modules

#import <IASDKCore/IASDKCore.h>
#import <IASDKMRAID/IASDKMRAID.h>
#import <IASDKVideo/IASDKVideo.h>
  1. Create a properties for all types of controllers and for all content controllers.
    For example:

Creating Properties

@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;
  1. Create the user data object for better ad targeting:

Creating the User Data Object

IAUserData *userData =
[IAUserData build:^(id<IAUserDataBuilder>  _Nonnull builder) { 
    builder.age = 34;     
    builder.gender = IAUserGenderTypeMale;    
    builder.zipCode = @"90210";
}];

Note

The initialization is performed via builder block - the block runs on the same thread that it is invoked from, and is synchronous (like the enumerateObjectsUsingBlock iOS method).

As a result, the special block treatment (such as weak references, etc...) is not needed.

  1. The ad request object initialization:

Initializing the Ad Request Object

IAAdRequest *adRequest =
[IAAdRequest build:^(id<IAAdRequestBuilder>  _Nonnull builder) { 
    builder.userData = userData; // pass here the user data object, if relevant;
    builder.useSecureConnections = NO;    
    builder.spotID = @"YOUR SPOT ID";    
    builder.timeout = 10;    
    builder.keywords = @"books, music";    
    builder.autoLocationUpdateEnabled = YES;
}];

- IAAdRequest Class

Note

To send secure requests only, please set useSecureConnections to YES.

  1. Initialize the MRAID Content Controller:

Initializing the Controller

IAMRAIDContentController *mraidContentController =
[IAMRAIDContentController build: 
  ^(id<IAMRAIDContentControllerBuilder>  _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;
  1. Declare your view controller as conforming to IAMRAIDContentDelegate protocol:

Declaring Your View Controller

@interface YourViewController () <IAMRAIDContentDelegate>

Note

Refer to this page for a full explanation of the MRAID Content Delegate Protocol.

  1. Initialize the Video Content Controller:

Initializing the Video Content Controller

IAVideoContentController *videoContentController =
[IAVideoContentController build: 
  ^(id<IAVideoContentControllerBuilder>  _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;
  1. Declare your view controller as conforming to IAVideoContentDelegate protocol:

Declaring Your View Controller

@interface YourViewController () <IAMRAIDContentDelegate, IAVideoContentDelegate>

Note

Refer to this page for a full explanation of the Video Content Delegate Protocol.

  1. Initialize the View Unit Controller:

Initializing the View Unit Controller

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

self.viewUnitController = viewUnitController; // the View Unit Controller should be retained by a client side;
  1. Initialize the Fullscreen Unit Controller:

Initializing the Fullscreen Unit Controller

IAFullscreenUnitController *fullscreenUnitController =
  [IAFullscreenUnitController build:^(id<IAFullscreenUnitControllerBuilder> _Nonnull builder)
   {
     builder.unitDelegate = self;
     // all the needed content controllers should be added to the desired unit controller:
     [builder addSupportedContentController:self.mraidContentController];
     [builder addSupportedContentController:self.videoContentController];
   }];
    
self.fsUnitController = fullscreenUnitController; // the Fullscreen Unit Controller should be retained by a client side;
  1. Declare your view controller as conforming to IAUnitDelegate protocol:

Declaring Your View Controller

@interface YourViewController () <IAUnitDelegate, IAMRAIDContentDelegate, IAVideoContentDelegate>

Note

Refer to this page for a full explanation of the Unit Delegate Protocol.

Initializing Your Ad Spot

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,    
  [builder addSupportedUnitController:self.viewUnitController];
  [builder addSupportedUnitController:self.fsUnitController];
}];

self.adSpot = adSpot; // the Ad Spot should be retained by a client side;
  1. Fetch the ad:

Fetching the Ad

// 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];
    }
  }
}];

You have now completed the integration.