【问题标题】:Getting unique ID of non-phone iDevices and Android tablets获取非手机 iDevices 和 Android 平板电脑的唯一 ID
【发布时间】:2011-08-29 21:02:29
【问题描述】:

我的应用使用设备的电话号码来获取有关用户联系人的有意义的信息。 它可以在 Android 和 iOS 上运行。

在电话上,我只是使用 10 位数(无国家代码)电话号码作为用户的唯一标识符。这甚至适用于 Android 模拟器(它有自己的失效号码),尽管 iPhone 模拟器返回一个空白号码(我可以很容易地忽略这种情况)。

现在我开始在非手机设备上进行测试。虽然他们仍然有可用的联系人,但他们不再有电话号码。一种简单的方法是在 iOS 中使用 UDID 以及在 Android 中使用的任何等价物。但是,我有 2 个问题需要解决:

  1. UDID 不统一。我需要一个 10 个字符的密钥。有没有办法将 n 个字符散列成 10 个字符,避免冲突? (我可以忍受非常低概率的碰撞)

  2. 更大的问题:我刚刚读到Apple is blocking UDID access as of iOS 5。如果需要维护一个 10 个字符的密钥,我应该使用什么来代替它?

感谢您的宝贵时间。

【问题讨论】:

    标签: android ios hash identifier udid


    【解决方案1】:

    您可以使用 MAC 地址 How can I programmatically get the MAC address of an iphone 。有一个解决方案可以从 github https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5 上的应用程序的 MAC 地址和捆绑标识符创建 UUID。

    我认为 iphone 上的 MAC 地址就足够了。 Mac 地址有 12 个字符,因此您只需决定如何将其压缩为 10 个字符。

    【讨论】:

      【解决方案2】:

      你可以使用任何你想要的哈希方法;如果您要求结果只有 10 个字符,您可以轻松地将较大的散列减少到 10 个字符 - 您可以将结果剪裁为 10 个字符,您可以将第 11 到 20 与第 1 到 10 进行异或(如果您的hash 有超过 20 个字符)等。

      Android 面临的更大挑战是找到唯一的设备 ID - Google 有一种机制,但它依赖于 OEM 合规性,而且所有设备的合规性并不统一。 Is there a unique Android device ID? 包含一些很好的信息。

      【讨论】:

      • 感谢您的想法。最终选择了 MAC 地址建议,但 Android 链接确实有帮助。
      【解决方案3】:

      检查一下它可能会有所帮助。这是来自 Localytics 开源 SDK

      /**
       * Gets a 1-way hashed value of the device's unique ID. This value is
       * encoded using a SHA-256 one way hash and cannot be used to determine what
       * device this data came from.
       * 
       * @param appContext
       *            The context used to access the settings resolver
       * @return An 1-way hashed identifier unique to this device or null if an
       *         ID, or the hashing algorithm is not available.
       */
      public static String getGlobalDeviceId(final Context appContext) {
          String systemId = System.getString(appContext.getContentResolver(),
                  System.ANDROID_ID);
          if (systemId == null) {
              return null;
          }
      
          try {
              MessageDigest md = MessageDigest.getInstance("SHA-256");
              byte[] digest = md.digest(systemId.getBytes());
              BigInteger hashedNumber = new BigInteger(1, digest);
              return new String(hashedNumber.toString(16));
      
          } catch (NoSuchAlgorithmException e) {
              return null;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-08
        • 2013-08-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多