Expo在不弹出的情况下获得唯一的设备ID

Expo在不弹出的情况下获得唯一的设备ID

本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:00