[Older versions < 1.11.0] Displaying a Player

Initialization

  1. Initialize the SDK. Call SDK initialization as soon as possible, preferably in application:didFinishLaunchingWithOptions: method:

AdPlayer.initSdk( storeURL: URL(string: ...)!) // app store url )

Calling any of the AdPlayer APIs before initialization will result in errors!

Before this method is called, the SDK will not perform any operations and will not use any resources (memory, cpu, network etc.).

  1. Initialize the player tags. Best to be called right after initialize. In case the tags belong to more than one publisher, this method must be called once per publisher.

let tag1 = AdPlayerTagConfiguration(tagId: tag1Id) // configure your tag here let tag2 = AdPlayerTagConfiguration(tagId: tag2Id) // configure your tag here let publisher = AdPlayerPublisherConfiguration(publisherId: publisherId, tag1, tag2) AdPlayer.initializePublisher(publisher)

 

At least one AdPlayerTagConfiguration must be provided in the constructor of AdPlayerPublisherConfiguration (a publisher configuration cannot be instantiated without tags).

Preparing the UI placement(s) of your player tag(s)

To display a player you must create an AdPlayerPlacementViewController with one of the previously initialized tag IDs, add it to your layout and notify the transition by calling placement.didMove(toParent: parent). Once the player tag is initialized and the AdPlayerPlacementViewController is visible on the screen, the player will be loaded and the content of the assigned player tag will be presented.

let placement = AdPlayerPlacementViewController(tagId: tagId) parent.addChild(placement) parent.view.addSubview(placement.view) placement.didMove(toParent: parent)