For the complete documentation index, see llms.txt. This page is also available as Markdown.

Expo

If you are using Expo to build your app.

Initialization allows the SDK to perform detections in the background. You must always initialize the SDK before interacting with it. Only a limited set of SDK methods are safe to invoke on an uninitialized SDK.

Steps

1

Setup the Sentiance Core Expo config plugin

The Sentiance Core config plugin is responsible for initializing the SDK during app startup. Make sure it is configured in your app.json before proceeding. Refer to the Core integration guide if you haven't set it up yet.

2

Ensure the SDK is initialized from JS/TS code

The Sentiance Core config plugin initializes the SDK asynchronously, so make sure to await ensureInitialized() before your first SDK call to make sure the SDK is ready. It resolves once the SDK is initialized, and throws an SdkInitializationError if initialization failed or was never triggered.

import SentianceCore, {
  SdkInitializationError,
} from "@sentiance-react-native/core";

try {
  // Resolves once native async init completes (immediately if already initialized).
  await SentianceCore.ensureInitialized();
  console.log("Sentiance SDK is initialized");

  // Safe to interact with the SDK from here on.
  const userExists = await SentianceCore.userExists();
  console.log("Sentiance user exists:", userExists);
} catch (err) {
  if (!(err instanceof SdkInitializationError)) {
    console.error("Unexpected error while awaiting Sentiance SDK init", err);
  } else {
    switch (err.reason) {
      case "NOT_TRIGGERED":
        // The native initializer was never called from Application.onCreate / AppDelegate.
        console.error("Sentiance SDK init was never triggered natively");
        break;
      case "EXCEPTION_OR_ERROR":
        console.error("Sentiance SDK init hit an exception or error:", err.message);
        break;
        
      // Handle the other cases here  
    }
  }
}
3

Next: User Creation

After having successfully initialized the Sentiance SDK, you must now create a user. To do so, follow the instructions on this page.

Last updated