Integrating Rewarded Ads

Init

Note

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

  1. Import all the IASDK modules into your desired view controller:
#import <IASDKCore/IASDKCore.h>
#import <IASDKVideo/IASDKVideo.h>
#import <IASDKMRAID/IASDKMRAID.h>
  1. Retain the Marketplace SDK entities. Declare a properties for the:
  • ad spot
  • unit controller
  • video + MRAID content controllers
@property (nonatomic, strong) IAAdSpot *adSpot;

@property (nonatomic, strong) IAFullscreenUnitController *unitController;

@property (nonatomic, strong) IAVideoContentController *videoContentController;
@property (nonatomic, strong) IAMRAIDContentController *mraidContentController;
  1. Create the user data object for a better ad targeting (optional):
IAUserData *userData =
[IAUserData build:^(id  _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 required.

  1. Create the ad request:
IAAdRequest *adRequest =
[IAAdRequest build:^(id  _Nonnull builder) { 
    builder.userData = userData; // pass here the user data object, if relevant;
    builder.spotID = @"YOUR SPOT ID";    
    builder.timeout = 5;    
    builder.keywords = @"books, music";
    builder.useSecureConnections = NO;
}];

Note

To force sending the secure requests only, set the useSecureConnections property to YES. Otherwise the Marketplace SDK evaluates whether it can send the unsecure request.

  1. Initialise the Video Content Controller:
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;
  1. Declare your view controller conforms to the IAVideoContentDelegate protocol:
@interface YourViewController () 

Note

Click here for a full explanation of the Video Content Delegate Protocol.

  1. Initialise the MRAID Content Controller:
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;
  1. Declare your view controller conforms to IAMRAIDContentDelegate protocol:
@interface YourViewController () <IAVideoContentDelegate, IAMRAIDContentDelegate> 

Note

Click here for a full explanation of the MRAID Content Delegate Protocol.

  1. Initialise the Fullscreen Unit Controller:
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;
  1. Declare your view controller conforms to IAUnitDelegate protocol:
@interface YourViewController () <IAVideoContentDelegate, IAMRAIDContentDelegate, IAUnitDelegate>

Note

Click here for a full explanation of the Unit Delegate Protocol.

  1. Initialise your Ad Spot:
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;

Fetching

Fetch the ad:

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

Mandatory protocol implementations

  1. A view controller for ad (and other related modal screens) presentation.
    - (UIViewController * _Nonnull)IAParentViewControllerForUnitController:(IAUnitController * _Nullable)unitController:
- (UIViewController * _Nonnull)IAParentViewControllerForUnitController:(IAUnitController * _Nullable)unitController {
    return self; // in case 'self' is a UIViewController subclass;
}
  1. Rewarded ad callback.
    - (void)IAAdDidReward:(IAUnitController * _Nullable)unitController:
- (void)IAAdDidReward:(IAUnitController * _Nullable)unitController {
    NSLog(@"The ad did reward.");
}

You have now completed the integration.