获取非电话 iDevices 和 Android 平板电脑的唯一 ID

发布于 2024-12-02 03:40:25 字数 588 浏览 3 评论 0原文

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

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

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

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

  2. 甚至还有一个更大的问题:我刚刚读到Apple 从 iOS 5 开始阻止 UDID 访问。再次需要维护 10 个字符的密钥时,我应该使用什么来代替它?

感谢您抽出时间。

My app uses a device's phone number to get meaningful information about the user's contacts.
It runs on Android and iOS.

On a phone, I simply use the 10-digit (no country code) phone number as the user's unique identifier. This even works on the Android simulator (which has its own defunct number), though the iPhone simulator returns a blank number (I can easily ignore this case).

Now I got to testing on non-phone devices. While they still have contacts available, they no longer have a phone number. An easy approach would be to use the UDID in iOS and whatever the equivalent is in Android. However, I have 2 problems I need solving:

  1. The UDID is not uniform. I need a 10 character key. Is there any way to hash n-characters into 10-characters, avoiding collisions? (I can live with very low probability collisions)

  2. Even a bigger issue: I just read that Apple is blocking UDID access as of iOS 5. What shall I use in its stead, again, with the need to maintain a 10-character key?

Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没有你我更好 2024-12-09 03:40:25

您可以使用MAC地址我如何以编程方式获取 iphone 的 MAC 地址 。有一个解决方案可以从 github 上的应用程序的 MAC 地址和捆绑包标识符创建 UUID https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5

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

You can use the MAC address How can I programmatically get the MAC address of an iphone . There is a solution out there that creates a UUID from the MAC address and the bundle identifier of the app on github https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5 .

I think the MAC address on the iphone is adequate. Mac addresses have 12 chars, so you just need to decide on how you want to squish it to 10 chars.

葬花如无物 2024-12-09 03:40:25

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

上更大的挑战将是找到唯一的设备 ID——Google 制定了一种机制,但它依赖于 OEM 合规性,而合规性是所有设备上的情况并不统一。 是否有唯一的 Android 设备 ID? 包含一些很好的信息。

You can use any hash method you wish; if you have a requirement that the result only be 10 characters, you can reduce a larger hash to 10 characters easily enough - you could clip the result at 10 characters, you could XOR the 11th through 20th with the 1st through 10th (cycling if your hash has more than 20 characters), etc.

The bigger challenge on Android is going to be finding a device ID which is unique -- there is a mechanism Google put in place, however it relies on OEM compliance and that compliance is not uniform across all devices. Is there a unique Android device ID? contains some good information though.

洛阳烟雨空心柳 2024-12-09 03:40:25

检查一下这个可能会有所帮助。这是来自 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;
    }
}

Check this out it might help. This is from Localytics Open Source 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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文