[UIDevice currentDevice] 可以使用什么?

发布于 2024-11-30 21:57:25 字数 75 浏览 4 评论 0原文

[UIDevice currentDevice] 可以包含什么,例如 uniqueIdentifier?谢谢!

What can be with [UIDevice currentDevice], such as uniqueIdentifier? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

A君 2024-12-07 21:57:26

对于 iOS 5,您可以使用以下方法创建一个新的但不是唯一的标识符:

CFUUIDRef UIID = CFUUIDCreate(NULL);
CFStringRef UIIDString = (CFUUIDCreateString(NULL, UIID));
NSString *string = [NSString stringWithFormat:@"%@",UIIDString];     

将其保存在文件中并像唯一标识符一样使用它

For iOS 5, you can create a new, but not unique identifier with this:

CFUUIDRef UIID = CFUUIDCreate(NULL);
CFStringRef UIIDString = (CFUUIDCreateString(NULL, UIID));
NSString *string = [NSString stringWithFormat:@"%@",UIIDString];     

Save it in a file and use it like unique identifier

旧故 2024-12-07 21:57:26

与 UIDevice 对象关联的所有属性和方法均在 UIDevice 类参考

要访问唯一标识符,您可以执行以下操作:

NSString *identifier = [[UIDevice currentDevice] uniqueIdentifier];

All the properties and methods associated with a UIDevice Object are described in the UIDevice Class Reference

To access the Unique Identifer, you can do something like:

NSString *identifier = [[UIDevice currentDevice] uniqueIdentifier];
伊面 2024-12-07 21:57:25

因为现在这有点过时了,我只是给出最新的答案。

因为 Apple 认为从 iOS 6 开始停止开发者使用 [[UIDevice currentDevice] uniqueIdentifier]; 是合适的,Suhail Patels< /code> 回答使用建议。他们现在已经开始告诉开发者使用[[UIDevice currentDevice]identifierForVendor];,但一些开发者对于是否仍然允许使用uniqueIdentifier感到困惑,即使他们仍然是否针对 iOS 5 及更低版本进行开发。 Apple 对此有点挑剔,只是说:

"Apps that use the `UDID` will be rejected in the App Store review process.." 

来吧,Apple 给我们提供更多细节。

无论如何,由于这背后的混乱,一些开发人员已经开始使用 OpenUDID 来获取唯一标识符。以下是一些有关如何使用它的代码:

    if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
        // Use: [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
        // Use: [OpenUDID value];
    }

编辑

由于 UDID 已被弃用,一些开发人员现在也认为开始使用 MAC 地址是合适的。这是因为 MAC 地址是基于硬件的,因此无法更改。对于那些想要获取 MAC 地址的人来说,苹果在 获取 MAC地址

Because this is slightly out of date now I am just giving an up to date answer.

Because Apple has seen fit to stop developers using the [[UIDevice currentDevice] uniqueIdentifier]; from iOS 6 onwards which Suhail Patels answer advices to use. They have now started telling developers to use [[UIDevice currentDevice] identifierForVendor];, but some developers are confused on whether they are still allowed to use uniqueIdentifier even if they are still developing for iOS 5 and below or not. Apple have been a bit fussy about this just saying :

"Apps that use the `UDID` will be rejected in the App Store review process.." 

Come on Apple give us a bit more detail.

Anyway because of the confusion behind this some developers have started using OpenUDID to get a unique identifier. Here is some code on how it can be used:

    if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
        // Use: [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
        // Use: [OpenUDID value];
    }

EDIT

Some developers have also now seen fit to start using the MAC Address since UDID has been deprecated. This is because the MAC addresses are hardware based and therefore can't be changed. For those of you that which to go for the MAC Address way apple have provided some sample code on Getting MAC Address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文