description |
---|
SDK Initialization Steps |
Initialization sets up internal SDK components to allow the creation of a Sentiance user on the device, and perform detections in the background.
Only a limited set of SDK methods are allowed to be invoked before initializing the SDK.
Initialization must be done in the application:didFinishLaunchingWithOptions:
method of your AppDelegate
class. If you don't already have a custom AppDelegate set up, first create a new class that extends Application
.
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
@import SENTSDK;
In the application:didFinishLaunchingWithOptions:
method of your AppDelegate
class, call initializeWithOptions:launchOptions:
.
{% code title="AppDelegate.swift" %}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let result = Sentiance.shared.initialize(options: SENTOptions(for: .appLaunch))
if result.isSuccessful {
NSLog("Initialization succeeded")
}
return true
}
{% endcode %}
Initialization will normally succeed, unless an unexpected error or exception is encountered. In case of failure, you can check the reason via the returned result.
if result.isSuccessful {
NSLog("Initialization succeeded")
} else {
NSLog("Initialization failed with reason \(result.failureReason)")
}
{% hint style="warning" %}
You must initialize the SDK during app startup, before application:didFinishLaunchingWithOptions:
returns. Therefore, you must do it synchronously on the main thread. If you plan to add a remote flag to control the initialization (e.g. Firebase Remote Config), make sure the check is synchronous (e.g. utilizing a cached flag). See here to learn more about why this is important.
{% endhint %}
To learn more about Initialization, see the SDK Initialization page.