繁体   English   中英

[UIDevice currentDevice]可以使用什么?

[英]What can be used with [UIDevice currentDevice]?

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

因为这有点过时了,所以我现在给出一个最新的答案。

因为Apple认为适合阻止开发人员使用[[UIDevice currentDevice] uniqueIdentifier]; iOS 6开始, Suhail Patels回答要使用的建议。 他们现在已经开始告诉开发人员使用[[UIDevice currentDevice] identifierForVendor]; ,但是即使他们仍在为iOS 5和更低iOS 5开发,一些开发人员对于是否仍然允许使用uniqueIdentifier感到困惑。 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地址”中提供了一些示例代码。

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

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

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

与UIDevice对象关联的所有属性和方法在《 UIDevice类参考》中进行了描述。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM