Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

android - Expo get unique device id without ejecting

This library allows you to get unique device id / Mac address of Android devices, which doesn't change after reinstallation.

Expo.Constants.deviceId changes after every reinstallation (even if the app version number is the same).

Is there a way to get an unique id for Android that doesn't change after reinstallation (at least for if it's the same version), without ejecting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Expo IOS theres currently very limited options, Since Apple forbids getting private device info. We will need to create our own unique identifier below.

My solution is a combination of uuid and Expo SecureStore works for IOS and Android.

import * as SecureStore from 'expo-secure-store';
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';


let uuid = uuidv4();
await SecureStore.setItemAsync('secure_deviceid', JSON.stringify(uuid));
let fetchUUID = await SecureStore.getItemAsync('secure_deviceid');
console.log(fetchUUID)

This solution will work even if app gets reinstalled, or if user switches devices and copy's all data to new device. (Expo.Constants.deviceId is deprecated and will be removed in SDK 44)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...