SpotX pre-integration

To configure the player to play SpotX ads, Google IMA should be configured.

let playerConfig = THEOplayerConfiguration(googleIMA: true)
var theoplayer = THEOplayer(configuration: playerConfig)

Next add a SpotX ad configuration to the sources

Note: from SDK ≥ 1.6.2 the 'ifa' parameter is automatically added in the SDK, so you don't need to specify it manually anymore.

let typedSource = TypedSource(src: "", type: "application/x-mpegurl")
let appParam = SpotXData(stringParameters: ["bundle": "", "name": "MyAppName"])
let deviceParam = SpotXData(stringParameters: ["ifa": "38400000-8cf0-11bd-b23e-10b96e40000d"], intParameters: ["dnt": 1, "lmt": 1], geoParameter: Geo(lat: -24.378528, lon: -128.325119))
let custom = SpotXData(stringParameters: ["my-custom-label": "my-custom-value"]) let adDesc = SpotXAdDescription(id: "12345", cacheBuster: true, app: app, device: device, user: user, custom: custom)
let source = SourceDescription(source: typedSource, ads: [adDesc])
theoplayer.source = source

Get default user-agent for your SpotX analytics

From THEOplayer iOS SDK 2.64 THEOplayer removed the default user-agent generation for SpotX analytics (if it is not specified by the user) to be compatible with the iOS 13 AppStore requirements.

If your implementation is still relies on this default user-agent, here is a way to get it:

let webView = WKWebView(frame: // keep a strong reference for the WebView somewhere
webView.evaluateJavaScript("navigator.userAgent", completionHandler: { (result, error) in
if let deviceUserAgent = result as? String {

And set it on your SpotX analytics in deviceParameters with "ua" key:

let deviceParam = SpotXData(stringParameters: ["ifa": "38400000-8cf0-11bd-b23e-10b96e40000d", "ua": "MY_USER_AGENT"], intParameters: ["dnt": 1, "lmt": 1], geoParameter: Geo(lat: -24.378528, lon: -128.325119))
let spotXAdDescription = SpotXAdDescription(id: "12345", cacheBuster: true, app: ..., device: deviceParam, user: ..., custom: ...)

YoSpace Server Side Ad integration

To configure the player to include server-side advertising from YoSpace, only the source configuration should be configured.

let typedSource = TypedSource(src: ",hlssample.m3u8?", type: “application/x-mpegurl”, ssai: YospaceServerSideAdInsertionConfiguration(streamType: .live))
let source = SourceDescription(source: typedSource)
theoplayer.source = source


If you need you can configure Yospace logging on the Yospace TypedSource:

YospaceServerSideAdInsertionConfiguration(streamType: .live, logLevel: YospaceLogLevelConfiguration(id3Tags: true, rawXml: true))


You can have access to the underlying Yospace session to register your own analytics listeners:

WARNING! this gives you access to the Yospace Session object! Be careful with your modifications, it could affect how THEOplayer works!)

theoplayer.yospace?.addEventListener(type: YospaceEventTypes.YOSPACE_SESSION_CHANGED, listener: { (e) in
    print("Yospace session received ", e)
    theoplayer.yospace?.activeSession?.subscribe(toAnalyticEvents: YourYospaceAnalyticsListener())

class YourYospaceAnalyticsListener : NSObject, YSAnalyticObserver {
    func advertDidStart(_ advert: YSAdvert) -> [Any]? {
        print("Yospace advertDidStart")
        return nil
    func advertDidEnd(_ advert: YSAdvert) {
        print("Yospace advertDidEnd")

To use Yospace classes and object, you need to include the Yospace headers in your project: link