iOS 唯一用户标识符 [英] iOS unique user identifier

查看:57
本文介绍了iOS 唯一用户标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iphone 编写一个应用程序,它使用 REST 与我的服务器进行通信.主要问题是,我需要以某种方式识别用户.不久前,我们还被允许使用 UDID,但现在已经不允许了.那我应该用什么代替呢?我在 iphone 上需要某种标识符,所以用户将删除应用程序,重新安装它,他将获得相同的 ID.

I'm writting an application for iphone, which communicates with my server using REST. The main problem is, I need to identify user somehow. Not so long ago, we were allowed to use UDID, but now its not allowed anymore. So what should I use instead? I need some kind of identifier on iphone, so user will delete application, install it again, and he will get same id.

推荐答案

首先,UDID是仅在 iOS 5 中被弃用.这并不意味着它已经消失(尚未).

Firstly, the UDID is only deprecated in iOS 5. That doesn't mean it's gone (yet).

其次,你应该问问自己是否真的需要这样的东西.如果用户获得一台新设备并在其上安装您的应用怎么办?相同的用户,但 UDID 已更改.同时,原始用户可能已经卖掉了他的旧设备,所以现在一个全新的用户安装了您的应用,并且您认为根据 UDID 是另一个人.

Secondly, you should ask yourself if you really need such a thing. What if the user gets a new device and installs your app on that? Same user, but the UDID has changed. Meanwhile, the original user might have sold his old device so now a completely new user installs your app and you think it's a different person based on the UDID.

如果您不需要 UDID,请使用 CFUUIDCreate() 创建唯一 ID 并在第一次启动时将其保存为用户默认值(使用 CFUUIDCreateString()> 首先将 UUID 转换为字符串).它将在备份和恢复中幸存下来,甚至在原始用户切换到新设备时也会出现.UDID 在很多方面都是更好的选择.

If you don't need the UDID, use CFUUIDCreate() to create a unique ID and save it to the user defaults on the first launch (use CFUUIDCreateString() to convert the UUID to a string first). It will survive backups and restores and even come along with the original user when they switch to a new device. It's in many ways a better option that the UDID.

如果您确实需要一个唯一的设备标识符(这听起来不像您需要的),请按照 Suhail 的回答中指出的那样获取 MAC 地址.

If you really need a unique device identifier (it doesn't sound like you do), go for the MAC address as pointed out in Suhail's answer.

这篇关于iOS 唯一用户标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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