The SDK can signal SDK status updates to JavaScript without being invoked directly. You can subscribe to these status updates:
import { NativeEventEmitter } from "react-native";
const sentianceEmitter = new NativeEventEmitter(RNSentiance);
const subscription = sentianceEmitter.addListener(
"SENTIANCE_STATUS_UPDATE_EVENT", (res) => {
// Returns SDK status
});
// Don't forget to unsubscribe, typically in componentWillUnmount
subscription.remove();
Get the SDK version
// returns Promise<string>
const version = await RNSentiance.getVersion();
Get the user ID
If the SDK is initialized, you can get the user ID as follows. This user ID will allow you to interact with the APIs from Sentiance. You need a token and a user ID to authorize requests and query the right data.
If the SDK is initialized, you can get a user access token as follows. This token will allow you to interact with the APIs from Sentiance. You need a token and a user ID to authorize requests and query the right data. If the token has expired, or will expire soon, the SDK will get a new bearer token before returning it. Generally, this operation will complete instantly by returning a cached bearer token, but if a new token has to be obtained from the Sentiance API, there is a possibility that it will fail
Custom metadata allows you to store text-based key-value user properties on the Sentiance platform, such as application related properties, which you can then obtain when processing data offloads (generated by Sentiance).
When you call startTrip on the SDK, you override automatic SDK detections and force trip data collection, until you call stopTrip, or until the trip times out (only applicable to the triggered trip SDK flavor). startTrip accepts a metadata object and a transport mode hint (numeric) as parameters.
If you want to override the default SDK data submission behavior, you can initiate a forced submission of detections. Ideally, you use this method only after explaining to the user that your app will consume more bandwidth in case the device is not connected to Wi-Fi.
try {
// returns Promise<boolean>
await RNSentiance.submitDetections();
} catch (err) {
// Something went wrong with submitting data, for more information, see the error variable
}
Disk, mobile network and Wi-Fi quotas
The usage and limits of network and disk capacity in bytes can be obtained using the getWiFiQuotaUsage, getWiFiQuotaLimit and similar methods on the Sentiance SDK interface.
Update the SDK foreground notification (ANDROID ONLY)
Updates the title and text of SDK notification. After calling this method, any notification shown by the SDK will be updated.
Note that this change is valid only during the process's lifetime. After the app process restarts, the SDK will display the default notification.
// returns Promise<boolean>
await RNSentiance.updateSdkNotification("RN SDK Sample", "SDK is running");
Resetting the SDK
To delete the Sentiance user and its data from the device, you can reset the SDK by calling RNSentiance.clear. This allows you to create a new Sentiance user by reinitializing the SDK, and linking it to a new external ID.
try {
// returns Promise<boolean>
await RNSentiance.clear();
// The SDK was successfully cleared and reset
} catch (err) {
// Resetting the SDK failed
// err.name has three values: SDK_INIT_IN_PROGRESS, SDK_RESET_IN_PROGRESS, SDK_RESET_UNKNOWN_ERROR
}
Determine if the app should initialize Sentiance SDK natively
To make user linking possible, the first SDK initialization should be executed in JS. After it completes successfully, await RNSentiance.enableNativeInitialization() should be invoked.
In AppDelegate (iOS) and MainApplication (Android), isNativeInitializationEnabled can be used to determine if the SDK should be initialized natively.
To disable native initialization, invoke await RNSentiance.disableNativeInitialization().
Vehicle Crash Event Detection
Listen to vehicle crash events:
import { NativeEventEmitter } from "react-native";
const sentianceEmitter = new NativeEventEmitter(RNSentiance);
const vehicleCrashEventSubscription = sentianceEmitter.addListener(
"VehicleCrashEvent",
(event: VehicleCrashEvent) => {}
);
RNSentiance.listenVehicleCrashEvents();
// To unsubscribe
vehicleCrashEventSubscription.remove();