Integrating HTML/MRAID Banner Ads

Note

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

Integrating HTML/MRAID Ads

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

Importing the SDK

#import <IASDKCore/IASDKCore.h>
#import <IASDKMRAID/IASDKMRAID.h>
  1. Each IASDK module should be retained by the “client side”, hence their properties should be added. For example:

Adding Properties

@property (nonatomic, strong) IAAdSpot *adSpot;
@property (nonatomic, strong) IAViewUnitController *viewUnitController;
@property (nonatomic, strong) IAMRAIDContentController *mraidContentController;
  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, that 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:

Creating 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 MRAID Content 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 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];
}];

self.viewUnitController = viewUnitController; // the View Unit Controller should be retained by a client side;
  1. Declare your view controller as conforming to IAUnitDelegate protocol:

Decalring Your View Controller

@interface YourViewController () <IAUnitDelegate, IAMRAIDContentDelegate>

Note

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

  1. Initialize your Ad Spot:

Initializing the 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,
    // (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;
  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 (adSpot.activeUnitController == weakSelf.viewUnitController) {
      [weakSelf.viewUnitController showAdInParentView:weakSelf.view];        
    }    
  }
}];

You have now finished integrating Video Ads!

You can now begin to integrate other ad types:

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request