SDK Initialization
The SDK initial configuration consists of a fixed short string. Substitute initialConfig for that string. The SDK can then be initialized as follows:
- Java
- Swift
try {
Approov.initialize(getApplicationContext(), initialConfig, "auto", null);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Approov initialization failed: " + e.getMessage());
}
do {
try Approov.initialize(initialConfig!, updateConfig:"auto", comment: nil)
} catch {
NSLog("Approov initialization failed: \(error.localizedDescription)")
}
On Android, Approov initialization requires the app Context. The parameter auto to the update configuration indicates that the SDK should automatically handle any dynamic configuration updates, storing them in the persistent storage for the app. The final comment string parameter should be set to null unless you are initializing with options orreinitializing the SDK.
If there is a problem with the initialization then an exception will be thrown and it will not be possible to execute further methods in the SDK.
The SDK may attempt to fetch information from the Approov servers as a background task as part of the initialize call. This will just fail silently if network connectivity is not available and will be retried when a subsequent SDK call is made that requires Approov server communication. You should make the initialize call as early as possible after the creation of the app to allow the background fetch to proceed while minimizing the latency for any subsequent Approov fetch operation.
From SDK version 3.5 onwards, if you attempt to initialize the SDK again with exactly the same set of parameters (initial configuration, update configuration and comment) that was used on the last successful initialization of the session then the call is simply ignored. The call will complete successfully with a false or NO return value indicating that no change was made to the initialized state.
The use of auto for the update configuration is only supported in 3.0.0 and later SDKs.
SDK Initialization Options
It is possible to provide some options to the SDK initialization using the comment parameter. To provide options the string should start with options: and then a number of comma separated options may be supplied from the following:
| Platform(s) | Option | Description |
| Android/iOS | did:<reinit-secret>:<new-did> | This provides a way to change the device ID reported by the SDK. This is only for use in very particular circumstances and can only be done if it has been enabled by Approov and you have been supplied with a specific reinit-secret which allows this. Please contact Approov support if wish to discuss enabling this. The new-did is the base64 encoded 128-bit device ID to be used. Note that this option requires that the SDK is initialized with an Extended SDK Configuration that was obtained after the capability was enabled. |
| Android/iOS | no-install-key | Disables the use of install keys by the SDK. By default attestations will still pass for SDKs initialized in this way, but if the option flag require-install-key is asserted then it will fail. |
| Android | prestart-isoproc | Enables an isolated process prestart even from the very first launch of the app after installation. See Isolated Process Prestart. |
By way of an example, a possible comment string might be options:no-install-key,did:RWhyLeMjEktRLmC7/kD39wbJMA8kDBpF05JrKT4XnE4=:++MySpecialDeviceID++w==.
Reinitializing the SDK
Under normal circumstances it is only permissible to initialize the SDK once, and any attempt to initialize it a second time will result in an error.
There is one particular use case for Approov where a single app might be associated with several different Approov accounts, that might be selected as the app runs. Note though that the Approov SDK can only be associated with one account at a time.
Reinitialization is explicitly marked by providing reinit to the comment parameter of the initialization call.
- Java
- Swift
try {
Approov.initialize(getApplicationContext(), initialConfig, "auto", "reinit");
} catch (IllegalArgumentException e) {
Log.e(TAG, "Approov reinitialization failed: " + e.getMessage());
}
do {
try Approov.initialize(initialConfig, updateConfig:"auto", comment:"reinit")
} catch {
NSLog("Approov reinitialization failed: \(error.localizedDescription)")
}
The SDK should not be reinitialized too frequently. The typical use case is that the reinitialization should only occur if the user of the app switches their account in some way, requiring access to a different set of backend APIs. Reinitialization should never be performed if there are in-flight asynchronous Approov fetches.
Reinitializing with a Specific Device ID
It is also possible to perform a reinitialization that can also change the current device ID. This is only for use in very particular circumstances and can only be done if the it has been enabled by Approov and you have been supplied with a specific reinit-secret which allows this. Please contact Approov support if wish to discuss enabling this.
The format of the comment string required is reinit:<reinit-secret>:<new-device_id> where reinit-secret is the secret supplied (normally a base64 string) and new-device-id is the base64 encoded 128-bit device ID to be used. This value may be supplied on the first or any subsequent initialize call to the SDK.
Note that the SDK must be reinitialized with an Extended SDK Configuration that was obtained after the feature was enabled.