如何在Flutter中获得唯一的设备ID? [英] How to get unique device id in flutter?
本文介绍了如何在Flutter中获得唯一的设备ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Android中,我们有Settings.Secure.ANDROID_ID
.我不知道iOS的等效功能.
是否可以使用flutter插件或在flutter中获取Android和IOS的唯一设备ID的方法?
In Android we have, Settings.Secure.ANDROID_ID
. I do not know the iOS equivalent.
Is there a flutter plugin or a way to get a unique device id for both Android and IOS in flutter?
推荐答案
有一个名为device_info的插件.您可以在此处获得它. 在此处查看官方示例 >
There is a plugin called device_info. You can get it here. Check the official example here
static Future<List<String>> getDeviceDetails() async {
String deviceName;
String deviceVersion;
String identifier;
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
try {
if (Platform.isAndroid) {
var build = await deviceInfoPlugin.androidInfo;
deviceName = build.model;
deviceVersion = build.version.toString();
identifier = build.androidId; //UUID for Android
} else if (Platform.isIOS) {
var data = await deviceInfoPlugin.iosInfo;
deviceName = data.name;
deviceVersion = data.systemVersion;
identifier = data.identifierForVendor; //UUID for iOS
}
} on PlatformException {
print('Failed to get platform version');
}
//if (!mounted) return;
return [deviceName, deviceVersion, identifier];
}
您可以将此UUID存储在钥匙串中.这样,您可以为设备设置唯一的ID.
You can store this UUID in the Keychain. This way you can set an unique ID for your device.
这篇关于如何在Flutter中获得唯一的设备ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文