iOS SDK Ads

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: "https://www.examples.com/index.m3u8", type: "application/x-mpegurl")
let appParam = SpotXData(stringParameters: ["bundle": "my.bundle.name", "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

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: "http://csm-e.cds1.yospace.com/csm/extlive/yospace02,hlssample.m3u8?yo.br=true&yo.ac=true", 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