【问题标题】:What can i use as a device identifier in flutter?我可以在颤动中使用什么作为设备标识符?
【发布时间】:2020-05-31 05:17:39
【问题描述】:

我正在构建一个应用程序,我需要为每台设备设置一个唯一标识符,即使用户卸载了该应用程序,我也不希望它发生变化,我应该使用什么?我不知道我应该寻找什么。我搜索了一下,我发现了一个名为 deviceid 的东西是否足够好? https://pub.dev/packages/device_id

【问题讨论】:

    标签: android ios flutter dart


    【解决方案1】:

    显然 device_id 插件在最新版本的颤振中存在一些错误。您可以改用device_info。 这是一个例子:

     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];
    }
    

    【讨论】:

    • 标识符 = data.identifierForVendor; //iOS 的 UUID 将在应用程序重新安装时更改。阅读docs
    【解决方案2】:

    最安全的方法是为用户建立一个注册。因此,如果用户想使用您的应用程序,他需要注册个人资料。每个帐户都有一个唯一标识符,即使用户重新安装应用程序,您也可以识别他。

    您链接的软件包也是可能的,但请记住越狱设备可能会更改设备 ID。

    我不是 100% 确定,但在 Swift/iOS 中,您可以使用 KeyChain。检查this package,也许它可以帮助你。您可以找到更多关于 KeyChain 的信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多