Initialize the iOS SDK
Best practice: Initialize the Experiences SDK as early as possible when your app loads (for example, in applicationDidFinishLaunching). Early initialization improves performance and keeps analytics stable.
The iOS SDK initialization section guides on setting up the Experiences SDK, detailing the method signature and parameters like API key, externalUserId, and more for custom configuration. It covers initialization errors like invalid API keys or network failures and emphasizes managing viewer sessions for personalized experiences.
SDK Init
func initialize(apiKey: String,
externalUserId: String? = nil,
restoreExternalUserId: Bool = true, // starting in v2 (2.0.0)
cachingSize: Int? = nil,
prefetchingPolicy: BlazeCachePolicyLevel = .Default,
geo: String? = nil,
forceLayoutDirection: BlazeLayoutDirection? = nil,
delegate: BlazeSDKDelegate? = nil,
externalUserToken: String? = nil,
resultBlock: BlazeResultBlock?)Description
Initialization method of the SDK.
Parameters:
| Parameter | Description |
|---|---|
| apiKey | The API key |
| externalUserId | The viewer ID for a logged-in viewer. Your app supplies this value. See Viewer ID specifications. |
| restoreExternalUserId | Starting in v2 (2.0.0), when true (the default) and no externalUserId is passed, the viewer ID from the previous launch is restored. Pass false to start this launch with an anonymous viewer. A stored viewer ID is then logged out, and if that logout fails, initialization fails. Ignored when externalUserId is passed. Until v2, restoreExternalUserId is not a parameter. |
| cachingSize | The amount of possible cached content size restricted in MBs |
| prefetchingPolicy | The level of content prefetching, which is determined by the BlazeCachePolicyLevel enum type. |
| geo | An optional country code to filter Geo-blocked content. This value overrides the default IP-based country detection used to define the viewer's location |
| forceLayoutDirection | Forces the layout direction of the SDK's screens: .ltr or .rtl. Optional. When nil (the default), the SDK doesn't force a direction. |
| delegate | An object that receives global delegate events callbacks. optional. |
| externalUserToken | The viewer token used for content entitlements and stream tokenization. Required when either is enabled for your app, which WSC Sports does per account. Held in memory only, so supply it on every launch. Optional; it can also be set later through setExternalUserToken. |
| resultBlock | A closure that captures success or a possible initialization error of BlazeSDK |
Initialization errors:
- invalidApiKey: Invalid API Key passed to the initializer. Please carefully check the provided API Key.
- networkFailure: Failed to initialize due to a network error.
- alreadyInitialized: SDK can be initialized only once.
- initializationIsRequired: SDK must be initialized before attempting to perform any operations.
- invalidGeoCode: The Geo code provided to the initialization method is not a valid ISO 3166 country code.
OverviewThe externalUserId parameter is used to uniquely identify a viewer session when initializing our SDK. This identifier serves as a key for customizing and tracking viewer-related activities during the SDK session.
- Overriding Behavior
If you re-initialize the SDK with a new externalUserId, the SDK will override the previous viewer identifier. The new externalUserId will be used for all subsequent activities and tracking. The previous viewer's unsynced activity is sent to WSC Sports, and their activity is cleared from the device. The previous identifier stays valid: set it again and that viewer's activity is restored.- Clearing Previous Viewer Identifier
Until v2, if you initialize the SDK with externalUserId set to nil, it clears the previous viewer identifier, effectively anonymizing the session. Activities in this state are not associated with any viewer identifier until a new externalUserId is set.
Starting in v2 (2.0.0), initializing without an externalUserId restores the viewer ID stored at the previous launch. To start a launch with an anonymous viewer instead, passrestoreExternalUserId: false: the stored viewer ID is logged out as part of initialization.- Recommended Practice
Due to our overriding and clearing behavior, it is crucial to use careful logic in your application to manage when and how to initialize new sessions. Make sure that you are intentionally setting or clearing externalUserId based on the desired outcome for viewer tracking and activity management.
Updated 10 days ago
