如何使用iOS创建GUID/UUID [英] How to create a GUID/UUID using iOS
问题描述
我希望能够在iPhone和iPad上创建GUID/UUID.
I want to be able to create a GUID/UUID on the iPhone and iPad.
目的是能够为所有唯一的分布式数据创建密钥.使用iOS SDK可以做到这一点吗?
The intention is to be able to create keys for distributed data that are all unique. Is there a way to do this with the iOS SDK?
推荐答案
[[UIDevice currentDevice] uniqueIdentifier]
返回iPhone的唯一ID.
Returns the Unique ID of your iPhone.
-[UIDevice uniqueIdentifier]
现在已弃用,并且正在使用的应用程序已从App Store拒绝.现在,下面的方法是首选方法.
-[UIDevice uniqueIdentifier]
is now deprecated and apps are being rejected from the App Store for using it. The method below is now the preferred approach.
如果需要创建多个UUID,只需使用此方法(对于ARC):
If you need to create several UUID, just use this method (with ARC):
+ (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (__bridge NSString *)string;
}
2014年1月29日: 如果您定位到iOS 6或更高版本,则可以使用更简单的方法:
Jan, 29 2014: If you're targeting iOS 6 or later, you can now use the much simpler method:
NSString *UUID = [[NSUUID UUID] UUIDString];
这篇关于如何使用iOS创建GUID/UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!