From 7e877e2c2cfeb3f356ac81a579711a530038f398 Mon Sep 17 00:00:00 2001 From: Aleksandr Zavadkin Date: Sat, 1 Nov 2025 16:37:08 +0900 Subject: [PATCH] docs(init): RN SDK init with Expo examples Signed-off-by: Aleksandr Zavadkin --- source/includes/_init.md.erb | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/source/includes/_init.md.erb b/source/includes/_init.md.erb index 52148bc..b200e3a 100644 --- a/source/includes/_init.md.erb +++ b/source/includes/_init.md.erb @@ -120,8 +120,39 @@ apply plugin: 'com.google.gms.google-services' yarn add <%= config[:rn_sdk_package_code] %>/rn-sdk yarn add @react-native-async-storage/async-storage + +/* Starting from 4.0.0 we support [Expo](https://expo.dev). This means that 'react-native-device-info' no longer is required.*/ + +/* If your application doesn't use Expo:*/ + yarn add react-native-device-info +/* If your application uses Expo, use this function to create a unique ID for each app Installation or create your own implementation*/ + +import * as Application from 'expo-application' +import * as SecureStore from 'expo-secure-store' +import 'react-native-get-random-values' +import { v4 as uuidv4 } from 'uuid' + +async function getDeviceId() { + if (Application.getAndroidId) { + return Application.getAndroidId() + } + + let uniqueId = await SecureStore.getItemAsync('uniqueId') + if (!uniqueId) { + uniqueId = uuidv4() + await SecureStore.setItemAsync('uniqueId', uniqueId) + } + + return uniqueId +} +/* RN SDK initialization with Expo will look like this:*/ + +const rnsdk = new <%= config[:rn_sdk_package_code] %>('YOUR_SHOP_ID', 'stream', false, true, { + id: await getDeviceId(), +}); + /* For push notifications also add: */ yarn add @react-native-firebase/app @@ -138,7 +169,13 @@ import <%= config[:rn_sdk_package_name] %> from '<%= config[:rn_sdk_package_code Set it to false if you want to manage token sending manually. */ -const sdk = new <%= config[:rn_sdk_package_name] %>("YOUR_SHOP_ID", "stream", "debug", autoSendPushToken); +const sdk = new <%= config[:rn_sdk_package_name] %>("YOUR_SHOP_ID", "stream", "debug", "autoSendPushToken"); + +/* RN SDK initialization with Expo will look like this. You can use your own function implementation to create a unique ID for each application installation*/ + +const sdk = new <%= config[:rn_sdk_package_code] %>('YOUR_SHOP_ID', 'stream', false, true, { + id: await getDeviceId(), +}); /* Initialization is async, so you have a method to test, if SDK is initialized or not: */