苹果官方给出的代替[UIDevice uniqueIdentifier]获取UDID的方法
2013-03-26 23:51
330 查看
感谢cocoachina会员freezn
转载:http://www.cocoachina.com/bbs/read.php?tid=95579
苹果官方给出的代替[UIDevice uniqueIdentifier]获取UDID的方法 (在iOS代码库中浏览本帖)
苹果关于UIDevice uniqueIdentifier的方法在文档中写到:uniqueIdentifier
An alphanumeric string unique to each device based on various hardware details. (read-only) (Deprecated in iOS 5.0. Instead, create a unique identifier specific to your app.)
@property (nonatomic, readonly, retain) NSString *uniqueIdentifier
Special Considerations
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.
主要看划线的部分,之前看论坛的上有人提到一些第三方的解决方案,但是实际上苹果也给出了替代的解决方案
根据划线部分的提示,实际上只需要在第一次使用程序的时候用CFUUIDCreate创造一个
UUID,然后将它存到NSUserDefault中,当做以前的UDID来用就行了
不过直接调用CFUUIDCreate得到的还不是一个直接的NSString,需要经过一些步骤才能转换成我们熟悉UDID形式:
以下是我自己最终完成的代码,包括了生成和存储的过程:
?
关于CFUUIDCreate,在苹果文档上有说明:
CFUUIDCreate
Creates a Universally Unique Identifier (UUID) object.
CFUUIDRef CFUUIDCreate (
CFAllocatorRef alloc
);
关于UUID这个东西 wiki百科上写:
“通用唯一识别码 (Universally Unique Identifier, UUID) 是一个软件建构的标准,亦为自由软件基金会 (Open Software Foundation, OSF) 的组织在分散式计算环境 (Distributed
Computing Environment, DCE) 领域的一部份。UUID 的目的,是让分散式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定。如此一来,每个人都可以建立不与其它人冲突的 UUID。在这样的情况下,就不需考虑数据库建立时的名称重复问题。目前最广泛应用的 UUID,即是微软的 Microsoft's Globally Unique Identifiers (GUIDs),而其他重要的应用,则有 Linux ext2/ext3 档案系统、LUKS 加密分割区、GNOME、KDE、Mac
OS X 等等。另外我们也可以在 e2fsprogs 套件中的 UUID 函式库找到实作。”
根据UUID产生的原理,你每产生一个,发生重复的概率非常低,几乎可以认为是不可能发生重复,所以这个UUID完全可以当做是对应一个使用这个软件的设备的唯一ID.
相关文章推荐
- 代替[UIDevice uniqueIdentifier]获取UDID的方法
- 获取UIDevice的uniqueIdentifier替代方法
- 获取UIDevice的uniqueIdentifier替代方法
- 去除 UIDevice uniqueIdentifier 方法调用时的警告
- 苹果UDID(uniqueIdentifier)的替代方案
- 【转】 iOS5:[UIDevice uniqueIdentifier]的替代方案
- 获取苹果手机UDID方法
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- (转)iOS5:[UIDevice uniqueIdentifier]的替代方案
- 获取ios设备系统信息的方法 之 [UIDevice currentDevice]
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- '-[UIDevice uniqueGlobalDeviceIdentifier]: unrecognized selector sent to instance 0x68170c0
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- UIDevice uniqueGlobalDeviceIdentifier(百度地图API的那些事)
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- NSUUID / CFUUIDRef / UIDevice -uniqueIdentifier / -identifierForVendor
- 获取UIDevice的uniqueIdentifier替代方法
- iOS5:[UIDevice uniqueIdentifier]的替代方案
- [转]UIDevice uniqueGlobalDeviceIdentifier(百度地图API的那些事)