Skip to main content

Getting started with THEOads on iOS

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

Prerequisites

  1. You need to have a THEOplayer license which is compatible with THEOads. This can be done through https://portal.theoplayer.com.

  2. You need a working THEOads signaling service.

  3. Add the THEOplayer iOS SDK to your project by following our Getting started guide. Make sure to set up a THEOads-compatible license in your app.

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

    1. Add the THEOplayer-Integration-THEOads pod to your Podfile:
    pod 'THEOplayer-Integration-THEOads', '~> 8.10.0'
    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 THEOads 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 THEOads, 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