[英]Alternative to [UIDevice currentDevice].identifierForVendor
[英]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.