如何使用 iOS 创建 GUID/UUID
我希望能够在 iPhone 和 iPad 上创建 GUID/UUID。
目的是能够为分布式数据创建唯一的密钥。 有没有办法使用 iOS SDK 来做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我希望能够在 iPhone 和 iPad 上创建 GUID/UUID。
目的是能够为分布式数据创建唯一的密钥。 有没有办法使用 iOS SDK 来做到这一点?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
返回您的 iPhone 的唯一 ID。
如果您需要创建多个 UUID,只需使用此方法(使用 ARC):
编辑:2014 年 1 月 29 日:
如果您的目标是 iOS 6 或更高版本,您现在可以使用更简单的方法:
Returns the Unique ID of your iPhone.
If you need to create several UUID, just use this method (with ARC):
EDIT: Jan, 29 2014:
If you're targeting iOS 6 or later, you can now use the much simpler method:
这是我正在使用的简单代码,符合 ARC。
Here is the simple code I am using, compliant with ARC.
在 iOS 6 中,您可以轻松使用:
Apple 文档
In iOS 6 you can easily use:
More details in Apple's Documentations
查看Apple开发人员文档,我发现 CFUUID 对象在 iPhone OS 2.0 及更高版本上可用。
Reviewing the Apple Developer documentation I found the CFUUID object is available on the iPhone OS 2.0 and later.
在Swift中:
In Swift:
最简单的技术是使用 NSString *uuid = [[NSProcessInfo processInfo]globalUniqueString]。 请参阅NSProcessInfo 类引用。
The simplest technique is to use
NSString *uuid = [[NSProcessInfo processInfo] globallyUniqueString]
. See the NSProcessInfo class reference.在Swift 3.0中
In Swift 3.0
我在这里上传了简单但快速的 ObjC Guid 类实现:obj -c GUID
它也可以解析各种字符串格式。
I've uploaded my simple but fast implementation of a Guid class for ObjC here: obj-c GUID
It can parse to and from various string formats as well.