Expo无需弹出即可获得唯一的设备ID

编程入门 行业动态 更新时间:2024-10-23 06:31:38
本文介绍了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

本文发布于:2023-11-30 03:24:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   设备   Expo   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!