Expo get unique device id without ejecting(Expo在不弹出的情况下获得唯一的设备ID)
问题描述
这个库允许您获取唯一的设备 ID/Mac 地址Android 设备,重新安装后不会改变.
This library allows you to get unique device id / Mac address of Android devices, which doesn't change after reinstallation.
Expo.Constants.deviceId
在每次重新安装后都会发生变化(即使应用版本号相同).
Expo.Constants.deviceId
changes after every reinstallation (even if the app version number is the same).
有没有办法在不弹出的情况下获得一个在重新安装后不会更改的 Android 唯一 ID(至少对于相同版本)?
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?
推荐答案
对于 Expo IOS,目前选项非常有限,因为 Apple 禁止获取私人设备信息.我们需要在下面创建自己的唯一标识符.
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.
我的解决方案是 uuid 和 Expo SecureStore 适用于 IOS 和 Android.
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)
即使重新安装应用程序,或者如果用户切换设备并将所有数据复制到新设备,此解决方案也将起作用.(Expo.Constants.deviceId
已弃用,将在 SDK 44 中删除)
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)
这篇关于Expo在不弹出的情况下获得唯一的设备ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Expo在不弹出的情况下获得唯一的设备ID


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01