如何在颤振中获得唯一的设备 ID? [英] How to get unique device id in flutter?

查看:24
本文介绍了如何在颤振中获得唯一的设备 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.

查看官方示例在这里

 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.

这篇关于如何在颤振中获得唯一的设备 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆