Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

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 tagConfig1 = AdPlayerTagConfiguration(tagId: tag1Id)
// configure your tag here

let tagConfig2 = AdPlayerTagConfiguration(tagId: tag2Id)
// configure your tag here

let publisher = AdPlayerPublisherConfiguration(publisherId: publisherId, tagConfig1, tagConfig2)

AdPlayer.initializePublisher(publisher)

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

All the player tags of this publisher that are expected to be presented in the application must be provided in the constructor of AdPlayerPublisherConfiguration.

A player tag that won’t be initialized successfully won’t be presented and won’t function!

A player tag should be initialized only once.

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

A player tag may be displayed only in one placement view controller. Displaying the same tag in multiple placement views is not supported and may lead to unexpected behavior.

Use your dashboard to configure the content, visualization and behavior of the player.

To display a player create an AdPlayerPlacementView with one of the previously initialized tag IDs, add it to your layout. Once the player tag is initialized and the AdPlayerPlacementView is visible on the screen, the player will be loaded and the content of the assigned player tag will be presented.

// ViewController.viewDidLoad
let placement = AdPlayerPlacementView(tagId: tagId)
placement.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(placement)
NSLayoutConstraint.activate([
    placement.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    placement.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    placement.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor)
])

By default, the SDK will set the placement’s height for you.
To override this behavior - set and implement “layoutDelegate“

// ViewController.viewDidLoad
placement.layoutDelegate = self
self.adPlacementHeightConstraint = placement.heightAnchor.constraint(equalToConstant: 0)

extension ViewController: AdPlacementLayoutDelegate {
    func adPlacementHeightWillChange(to newValue: CGFloat) {
       self.adPlacementHeightConstraint.constant = newValue
    }
}
  • No labels