Environment
public struct Environment
An SDK environment is an entry point for creating players and managing the global configuration.
Contents
This page displays:
Description
Create a single Environment instance when running the application. Use it to get YaPlayer instances.
Updating a configuration
You can update a configuration at any time without recreating the environment.
Network headers
Add global headers for all network request of the player.
Properties
|
Name |
Type |
Description |
|
|
|
Application ID from the current configuration. |
Initializers
@available(*, deprecated, renamed: "init(configuration:)", message: "Use API with Configuration instead")
public init(from: From)
Creates an SDK environment.
Parameters:
from: App ID.
public init(configuration: Configuration)
Creates an SDK environment with a specified configuration.
Parameters:
configuration: SDK configuration with the application ID and an optional user information provider.
Methods
public mutating func update(configuration: Configuration)
Updates the SDK configuration without recreating the environment.
Parameters:
configuration: New configuration.
public func setGlobalNetworkHeaders(_ headers: [String: String])
Sets HTTP headers added to all network requests of the player.
Parameters:
headers: Header dictionary in[name: value]format.
public func setNetworkHeaders(for endpoint: ContentIdEndpoint, headers: [String: String])
Sets HTTP headers for specific content requests.
public static func set(telemetryEndpoint: QuasiEndpoint?)
Overrides the endpoint for sending telemetry.
Parameters:
telemetryEndpoint: Custom endpoint ornilto restore the default value.
public static func set(perfEndpoint: QuasiEndpoint?)
Overrides the endpoint for sending performance data (perf events).
Parameters:
perfEndpoint: Custom endpoint ornilto restore the default value.
public func player() -> YaPlayer
Creates a new player instance.
The return value is a new YaPlayer instance.
Examples
let configuration = Configuration(from: From(raw: "my-ios-app"))
var environment = Environment(configuration: configuration)
// ViewController.swift
let player = environment.player()
let newConfig = Configuration(from: From(raw: "my-ios-app"), clientInfoProvider: provider)
environment.update(configuration: newConfig)
environment.setGlobalNetworkHeaders(["Authorization": "Bearer \(token)"])