如果用户卸载并重新安装应用程序,则由CFUUIDCreate
is创建的UUID是唯一的:每次你都会得到一个新的UUID.
But you might want it to be not unique, i. e. it should stay the same when the user uninstalls and re-installs the app. This requires a bit of effort, since the most reliable per-device-identifier seems to be the MAC address. You could query the MAC and use that as UUID.
Edit:当然,人们需要始终查询同一接口的MAC.我想最好的赌注是en0
美元.MAC始终存在,即使接口没有IP/已关闭.
Edit 2:正如其他人所指出的,iOS 6的首选解决方案是-[UIDevice identifierForVendor].在大多数情况下,你应该可以使用它作为旧-[UIDevice uniqueIdentifier]
的替代品(但苹果似乎希望你使用的是在应用首次启动时创建的UUID).
Edit 3:所以这个要点不会在注释噪音中丢失:不要使用MAC作为UUID,创建hash using the MAC.该散列每次都会产生相同的结果,即使是在重新安装和应用程序之间也是如此(如果散列是以相同的方式进行的).无论如何,现在(2013)已经没有必要这样做了,除非您需要iOS<;6.0上的"稳定"设备标识符.
Edit 4:在iOS 7中,苹果现在在查询MAC以明确阻止MAC as base for an ID方案时总是返回一个固定值.所以你现在真的应该使用-[UIDevice identifierForVendor]或者创建一个每次安装的UUID.