什么可以用?

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

所有与UIDevice对象关联的属性和方法都在UIDevice类的引用中进行了描述

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

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

因为这是稍微过时了,所以我只是给出一个最新的答案。

因为Apple已经适合阻止开发者使用[[UIDevice currentDevice] uniqueIdentifier];iOS 6Suhail Patels回答build议使用。 他们现在已经开始告诉开发者使用[[UIDevice currentDevice] identifierForVendor]; ,但是一些开发人员对于是否仍然允许使用uniqueIdentifier而感到困惑,即使他们仍然在开发iOS 5及以下版本。 Apple公司对此有点fu just,只是说:

 "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]; } 

编辑

一些开发人员现在也看到适合开始使用MAC地址,因为UDID已被弃用。 这是因为MAC地址是基于硬件的,因此不能改变。 对于那些去MAC地址的方式苹果提供了一些取得MAC地址的示例代码。

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

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

将其保存在一个文件中,并将其用作唯一标识符