A Closer Look at the iOS Sample App and Integration

A closer look at the source code of the sample app highlights the configuration required to build your own app:
  • The Header and Library Files
  • The Imports
  • ViewController Implementation, with Ads Manager
  • The Constants
  • View Set Up and OOIMAManager Initialization
  • Append Ad Tag Parameters to Ad Tag URL
  • Companion Ad Slot
  • Playing the Video
To begin, open the IMASampleApp/players/ViewController.m file.
Note: Get the latest version of the sample app from the The Ooyala Mobile SDK for iOS Sample Apps GitHub repository.

The Header and Library Files

For your Xcode project's Build Phase, be sure to include the following frameworks and libraries:
  • OoyalaSDK.framework
  • Either one of the following Google libraries from the GoogleIMALibraries directory, depending on if you are implementing Google IMA for Ad Mob or not:
    • libGoogleIMA3.a, for normal use. (The Ooyala-provided sample app uses this library.)
    • libGoogleIMA3ForAdMob.a, for use with Google IMA for AdMob.

For any new project to implement the Ooyala Google IMA SDK, you need to include all the header files from the OoyalaIMASDK-iOS/IMAHeaders subdirectory.

The Imports

The first three import statements pull in header definitions from the baseline Ooyala Mobile SDK.

The fourth import pulls in the Ooyala IMA Manager definitions.

#import <OoyalaSDK/ViewController.h>
#import <OoyalaSDK/OOOoyalaPlayerViewController.h>
#import <OoyalaSDK/OOOoyalaPlayer.h>
#import <OoyalaIMASDK/OOIMAManager.h>                           

ViewController Implementation, with Ads Manager

These lines define the ViewController implementation. Notice the definition of the adsManager property as an OOIMAManager-type interface.
@interface ViewController ()
@property (nonatomic, strong) OOOoyalaPlayerViewController *ooyalaPlayerViewController;
@property (nonatomic, strong) OOIMAManager *adsManager;
@end

@implementation ViewController

@synthesize ooyalaPlayerViewController;                 
For reference documentation about the OOIMAManager, see the OoyalaIMASDK-iOS/Documentation subdirectory.

The Constants

Whereas the sample app defines constants PCODE, EMBEDCODE, and PLAYERDOMAIN (see See the IMA Sample App in Action on iOS), you probably want to define variables, especially for the EMBEDCODE constant (asset ID or content ID).

View Set Up and OOIMAManager Initialization

Various view controllers combined with the OOIMAManager are included with the SDK. You can initialize the view with or without the Ooyala player. These and other definitions are in the header file IMAHeaders/OOIMAManager.h.

In the sample app, the view is setup and the adsManager object is initialized as an OOIMAManager:

 - (void)viewDidLoad
{
  [super viewDidLoad];
	ooyalaPlayerViewController = [[OOOoyalaPlayerViewController alloc] initWithPcode:PCODE domain:[[OOPlayerDomain alloc]
    initWithString:PLAYERDOMAIN];
 
  [self.videoView addSubview:ooyalaPlayerViewController.view];
 
  //Create the IMA Ad Manager
  self.adsManager = [[OOIMAManager alloc] initWithOoyalaPlayer:ooyalaPlayerViewController.player];             

Companion Ad Slot

A companion ad slot is defined for the adsManager object.

// Setup a companion ad view
  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    [self.adsManager addCompanionSlot:_largerCompanionSlot];
  }
  [self.adsManager addCompanionSlot:_smallerCompanionSlot];         

Append Ad Tag Parameters to Ad Tag URL

To append your own ad tags to your Google-supplied ad tag URL, you can use the setAdTagParameters() method.

  1. First, create an NSMutableDictionary named adTagParameters.
      //Create adTagParameters dict, fill it, and give it to the IMA Ad Manager  
      NSMutableDictionary *adTagParameters = [NSMutableDictionary dictionary];
      [adTagParameters setObject: EMBEDCODE forKey:@"vid" ];
      [adTagParameters setObject: @"[referrer_url]" forKey: @"url" ];
      [adTagParameters setObject: @"2" forKey: @"pod"];
      [adTagParameters setObject: @"2" forKey: @"ppos"];
      [adTagParameters setObject: @"preroll" forKey:@"vpos"];
      [adTagParameters setObject: @"2" forKey: @"mridx"];
     
      [self.adsManager setAdTagParameters: adTagParameters];
  2. For each of the ad tags you want to append, use setObject to define its value and forKey to define its name. Notice in the sample app that the ad tag vid is set to the EMBEDCODE constant (the video ID).
  3. After you have populated the dictionary, pass the adTagParameters dictionary to the setAdTagParameters function of the adsManager object (of type OOIMAManager).

    As an example, suppose you have an adTagUrl that looks like the following (this URL is broken across several lines for readability):

    http://pubads.g.doubleclick.net/gampad/ads?sz=400x300&iu=%2F6062%2Fhanna_MA_group%2Fwrapper_with_comp
    &ciu_szs=728x90&impl=s&gdfp_req=1&env=vp&output=xml_vast2
    &unviewed_position_start=1&m_ast=vast&correlator=[timestamp]              
    After setting up your ad tag parameters as shown in the sample app, the ad tag URL would look like this, with the extra tags highlighted:
    http://pubads.g.doubleclick.net/gampad/ads?sz=400x300&iu=%2F6062%2Fhanna_MA_group%2Fwrapper_with_comp
    &ciu_szs=728x90&impl=s&gdfp_req=1&env=vp&output=xml_vast
    2&unviewed_position_start=1&m_ast=vast&correlator=[timestamp]
    &mridx=2&vpos=preroll&ppos=2&vid=h5OWFoYTrG4YIPdrDKrIz5-VhobsuT-M&pod=2&url=[referrer_url]
    You can also override the base value of the ad tag URL itself. See the discussion in Overriding the Ad Tag URL on iOS.

Playing the Video

Finally, on the following line, the setEmbedCode() method is from the baseline Ooyala Mobile SDK. This line invokes the Ooyala player with the desired video identifier. It is a best practice to use a variable for the identifier (rather than the EMBEDCODE constant).
[ooyalaPlayerViewController.player setEmbedCode:EMBEDCODE];

Was this article helpful?