CLI
If you are building your app without using a Framework.
Steps
1
Initialize the Sentiance SDK for iOS
import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import RNSentianceCore
@main
class AppDelegate: RCTAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// ...
RNSentianceHelper().initializeAsync(launchOptions: launchOptions) { result, error in
if error == nil {
print("Sentiance SDK Initialization Success")
} else {
print("Sentiance SDK Initialization Failed: \(error!.failureReason)")
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}2
Initialize the Sentiance SDK for Android
import android.util.Log
import com.sentiance.react.bridge.core.SentianceHelper
private const val TAG = "Sentiance"
override fun onCreate() {
super.onCreate()
// ...
val sentianceHelper = SentianceHelper.getInstance(this)
sentianceHelper.initializeAsync()?.addOnCompleteListener { operation ->
if (operation.isSuccessful) {
Log.d(TAG, "Sentiance SDK Initialization succeeded")
} else {
Log.e(TAG, "Sentiance SDK Initialization failed with reason " + operation.error?.failureReason)
}
}
}adb logcat | grep Sentiance3
Ensure the SDK is initialized from JS/TS code
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
}
}
}Last updated