Skip to content

Commit 0cb9f53

Browse files
authored
docs(init): RN SDK init with Expo examples (#278)
Signed-off-by: Aleksandr Zavadkin <az@rees46.ru>
1 parent 6eb7c7d commit 0cb9f53

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

source/includes/_init.md.erb

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,39 @@ apply plugin: 'com.google.gms.google-services'
120120

121121
yarn add <%= config[:rn_sdk_package_code] %>/rn-sdk
122122
yarn add @react-native-async-storage/async-storage
123+
124+
/* Starting from 4.0.0 we support [Expo](https://expo.dev). This means that 'react-native-device-info' no longer is required.*/
125+
126+
/* If your application doesn't use Expo:*/
127+
123128
yarn add react-native-device-info
124129

130+
/* If your application uses Expo, use this function to create a unique ID for each app Installation or create your own implementation*/
131+
132+
import * as Application from 'expo-application'
133+
import * as SecureStore from 'expo-secure-store'
134+
import 'react-native-get-random-values'
135+
import { v4 as uuidv4 } from 'uuid'
136+
137+
async function getDeviceId() {
138+
if (Application.getAndroidId) {
139+
return Application.getAndroidId()
140+
}
141+
142+
let uniqueId = await SecureStore.getItemAsync('uniqueId')
143+
if (!uniqueId) {
144+
uniqueId = uuidv4()
145+
await SecureStore.setItemAsync('uniqueId', uniqueId)
146+
}
147+
148+
return uniqueId
149+
}
150+
/* RN SDK initialization with Expo will look like this:*/
151+
152+
const rnsdk = new <%= config[:rn_sdk_package_code] %>('YOUR_SHOP_ID', 'stream', false, true, {
153+
id: await getDeviceId(),
154+
});
155+
125156
/* For push notifications also add: */
126157

127158
yarn add @react-native-firebase/app
@@ -138,7 +169,13 @@ import <%= config[:rn_sdk_package_name] %> from '<%= config[:rn_sdk_package_code
138169
Set it to false if you want to manage token sending manually.
139170
*/
140171

141-
const sdk = new <%= config[:rn_sdk_package_name] %>("YOUR_SHOP_ID", "stream", "debug", autoSendPushToken);
172+
const sdk = new <%= config[:rn_sdk_package_name] %>("YOUR_SHOP_ID", "stream", "debug", "autoSendPushToken");
173+
174+
/* 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*/
175+
176+
const sdk = new <%= config[:rn_sdk_package_code] %>('YOUR_SHOP_ID', 'stream', false, true, {
177+
id: await getDeviceId(),
178+
});
142179

143180
/* Initialization is async, so you have a method to test, if SDK is initialized or not: */
144181

0 commit comments

Comments
 (0)