📖 Integration Guide: Using Peabody Native SDKs in Cross-Platform Apps

If you are building your mobile application using a cross-platform framework like Flutter, React Native, or Unity, you can still leverage the full power of the Peabody Compliance Native SDKs.

Because compliance and location triangulation require direct access to low-level OS APIs (like CoreTelephony on iOS or TelephonyManager on Android), we maintain our core logic in Native Swift and Native Kotlin. To use these in your project, you will implement a "Bridge" or "Platform Channel."

1. Architectural Overview

The "Bridge" pattern allows your cross-platform code (Dart, JavaScript, or C#) to send messages to the native side, execute Peabody SDK methods, and receive the results back.

2. Implementation Guide by Framework

A. Flutter (Platform Channels)

Flutter uses MethodChannel to communicate with native code.

  • Step 1 (Native iOS): In your AppDelegate.swift, create a FlutterMethodChannel. When a specific method is called (e.g., getComplianceStatus), invoke the Peabody iOS SDK.
  • Step 2 (Native Android): In your MainActivity.kt, override configureFlutterEngine and set up a MethodChannel to call the Peabody Android SDK.
  • Step 3 (Dart): Use platform.invokeMethod('getComplianceStatus') to trigger the check and await the result.

B. React Native (Native Modules)

React Native uses "Native Modules" to expose Swift/Java classes to JavaScript.

  • Step 1 (Native): Create a wrapper class that implements RCTBridgeModule (iOS) or BaseJavaModule (Android).
  • Step 2 (JS): Import the module from NativeModules and call your functions as standard asynchronous JavaScript functions.

C. Unity (Native Plugins)

Unity communicates with native libraries through C# wrappers.

  • Android: Drop our .aar file into Assets/Plugins/Android and use AndroidJavaObject to call SDK methods.
  • iOS: Place the .xcframework in Assets/Plugins/iOS and use [DllImport("__Internal")] to bridge C# to the native C-interface of our SDK.

3. Best Practices for Developers

To ensure a smooth integration, we recommend the following:

  • Consistent Naming: Use the same method names across your Flutter/RN/Unity code and our native SDK identifiers (e.g., verifyLocation).
  • Error Handling: Always wrap native calls in try-catch blocks. If the user denies permissions, the Native SDK will throw an error that should be handled gracefully in your UI.
  • Asynchronous Execution: Location triangulation and compliance checks are network-bound. Ensure you are using async/await patterns to keep your app UI responsive.

4. Why Native SDKs?

You might wonder why we don't provide a pure JavaScript or Dart library.

  • Direct Hardware Access: We access cellular radio data and hardware sensors that cross-platform abstractions often "sanitize" or hide.
  • Security: Our Native SDKs are compiled binaries, protecting the integrity of the compliance checks from tampering at the script level.
  • Performance: Native code handles the complex math of triangulation without impacting your app's frame rate.

Next Step:

We are currently finalizing "Drop-in" wrappers for Flutter and React Native. If you would like to be an early tester for these pre-built bridges, please contact our support team or check our GitHub for the latest .zip samples.