During initialization, the Sentiance SDK will construct all the components necessary to do detections, networking, and maintenance work.
The first time the SDK is initialized, a unique ID will be assigned to the device. All detections made on this device will be tagged with this ID as they get uploaded to the server to create a user timeline. Additionally, a configuration will be loaded from the server to determine detection parameters like location request intervals, sensors to record, and sampling rates. Last but not least, the SDK will schedule jobs and alarms for purposes of uploading data to the server and performing internal maintenance.
Subsequent initializations will ensure the SDK components are constructed and ready to handle incoming broadcast intents and alarms.
Once the Sentiance SDK has been initialized, it will set jobs, alarms, and geofences as part of the detection process. When your app is not running and a geofence event occurs, the system will start the process and deliver the broadcast intent or notification directly to the SDK. Therefore, the SDK must already be initialized before handling this event.
Initializing the SDK in the
didFinishLaunchingWithOptions method of your
AppDelegate class will ensure the SDK components are constructed, since these methods are guaranteed to finish before an intent or a notification is delivered to any broadcast receiver / delegate function.
Another important consideration is that when initializing inside
didFinishLaunchingWithOptions, it must be done synchronously on the main application (UI) thread. When
didFinishLaunchingWithOptions is finished,
init should have already returned. Therefore, using
Handler.post(Runnable) is not permitted.
You should only ever call
initWithConfig if the SDK has not been initialized. Calling these methods more than once will throw an
NSException. This is intentional to guarantee single execution of the logic you've implement in the success method of your initialization callback.
To check whether the SDK has been initialized, call
getInitState. This will return one of the following enums: