Skip to main content

Getting started with OptiView Ads on iOS

This guide will get you started to integrate OptiView Ads in your OptiView Player iOS SDK: configure the license, update dependencies and set the source description.

Prerequisites

  1. You need to have an OptiView Player license which is compatible with OptiView Ads. This can be done through the player portal.

  2. You need a correctly deployed OptiView Ads signaling service.

  3. Add the OptiView Player iOS SDK to your project by following our Getting started guide. Make sure to set up an OptiView Ads-compatible license in your app.

  4. Add the OptiView Ads integration as a dependency to your project:

    1. Add the THEOplayer-Integration-THEOads pod to your Podfile:
    pod 'THEOplayer-Integration-THEOads', '~> <YOUR_INTEGRATION_VERSION>'
    1. Install the new pod:
    pod install
  5. Add Google IMA SDK as a dependency to your project:

    1. The THEOplayer-Integration-THEOads pod has a dependency on GoogleAds-IMA-iOS-SDK which should be installed automatically.

Integration

To make use of the OptiView Ads integration, create and add the THEOadsIntegration to your THEOplayer instance:

import UIKit
import THEOplayerSDK
import THEOplayerTHEOadsIntegration

class ViewController: UIViewController {
var theoplayer: THEOplayer!
var theoads: THEOadsIntegration!

override func viewDidLoad() {
super.viewDidLoad()
self.theoplayer = THEOplayer(configuration: THEOplayerConfigurationBuilder().build())
self.theoplayer.frame = view.bounds
self.theoplayer.addAsSubview(of: view)
self.theoads = THEOadsIntegrationFactory.createIntegration(on: self.theoplayer)
self.theoplayer.addIntegration(self.theoads)
}

}

Then, configure a source containing a THEOAdDescription:

import UIKit
import THEOplayerSDK
import THEOplayerTHEOadsIntegration

class ViewController: UIViewController {
var theoplayer: THEOplayer!
var theoads: THEOadsIntegration!

override func viewDidLoad() {
super.viewDidLoad()
self.theoplayer = THEOplayer(configuration: THEOplayerConfigurationBuilder().build())
self.theoplayer.frame = view.bounds
self.theoplayer.addAsSubview(of: view)
self.theoads = THEOadsIntegrationFactory.createIntegration(on: self.theoplayer)
self.theoplayer.addIntegration(self.theoads)

let source = "PATH-TO-SIGNALING-SERVER/hls/MANIFEST-URI"
let typedSource = TypedSource(
src: source,
type: "application/x-mpegurl",
hlsDateRange: true
)
let theoad = THEOAdDescription(
networkCode: "NETWORK-CODE",
customAssetKey: "CUSTOM-ASSET-KEY"
)
let sourceDescription = SourceDescription(source: typedSource, ads: [theoad])
self.theoplayer.source = sourceDescription
self.theoplayer.play()
}

}
  • Notice that the src is different as usual. For OptiView Ads, a signaling server needs to be set up which acts as a proxy to parse the given manifest and insert the ad interstitials. More information can be found here.
  • The hlsDateRange flag needs to be set to true as the ad markers are done using EXT-X-DATERANGE tags.
  • The ads array needs to contain a THEOAdDescription. Furthermore, the networkCode and customAssetKey needs to be set according to your configured Google account.

More information