Flutter
Steps
1
Initialize the Sentiance SDK for iOS
import Flutter
import UIKit
import sentiance_core
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
SentianceCorePlugin.shared.initializeAsync(launchOptions: launchOptions) { result, error in
if result != nil {
print("Sentiance SDK initialization succeeded")
} else {
print("Sentiance SDK initialization failed, reason: \(String(describing: error?.failureReason))")
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}2
Initialize the Sentiance SDK for Android
package com.your.domain
import android.app.Application
import android.util.Log
import com.sentiance.core_plugin.CorePlugin
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
CorePlugin.initializeAsync(this)
.addOnCompleteListener { op ->
if (op.isSuccessful) {
Log.d("Sentiance", "Sentiance SDK initialization succeeded")
} else {
Log.e("Sentiance", "Sentiance SDK initialization failed, reason: ${op.error?.failureReason}")
op.error?.throwable?.let { Log.e("Sentiance", "throwable: ${it.message}") }
}
}
}
}
adb logcat | grep Sentiance3
Ensure the SDK is initialized from Dart code
import 'package:sentiance_core/sentiance_core.dart';
try {
await SentianceCore.ensureInitialized();
// The SDK is initialized. It is now safe to call other SDK methods.
} on SdkInitializationError catch (e) {
switch (e.reason) {
case SdkInitializationFailureReason.notTriggered:
// Init was never started, or was started late / off the main thread.
// Make sure initializeAsync runs synchronously from your native entry point.
break;
case SdkInitializationFailureReason.exceptionOrError:
// An error occurred during initialization, or the native reason was unrecognized.
break;
// Handle the other cases here
}
print('Sentiance SDK initialization failed: ${e.reason}, ${e.message}');
} on PlatformException catch (e) {
// An unexpected error occurred while talking to the host platform.
print('Unexpected error: ${e.message}');
}Last updated