刚刚发现,UIDevice uniqueIdentifier属性在iOS 5中已弃用,在iOS 7及以上版本中不可用。似乎没有可供选择的方法或属性。

我们现有的许多应用程序都紧密依赖于这个属性来唯一地识别特定的设备。今后我们该如何处理这个问题?

2011-2012年的文件建议:

特殊注意事项 不要使用uniqueIdentifier属性。创建特定的唯一标识符 你可以调用CFUUIDCreate函数来创建一个UUID,然后写入 使用NSUserDefaults类将它转换到默认数据库。

但是,如果用户卸载和重新安装应用程序,这个值就不一样了。


当前回答

您已经可以使用Apple UDID的替代方案了。gekitz在UIDevice上写了category,它会根据设备mac地址和包标识符生成某种UDID。

你可以在github上找到代码

其他回答

从iOS 7开始,苹果在所有公共api中都隐藏了UDID。任何以FFFF开头的UDID都是假ID。以前工作的“发送UDID”应用程序不能再用于为测试设备收集UDID。(叹息)

当设备连接到XCode(在管理器中)时,UDID会显示出来,当设备连接到iTunes时(尽管你必须单击“Serial Number”才能显示标识符)。

如果你需要获取设备的UDID来添加到配置配置文件中,并且不能自己在XCode中完成,你将不得不从iTunes中复制/粘贴它。

自iOS 7发布以来,是否有一种方法可以在PC/Mac上不使用iTunes获得UDID ?

我们可以在ios7中使用identifierForVendor,

-(NSString*)uniqueIDForDevice
{
    NSString* uniqueIdentifier = nil;
    if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) { // >=iOS 7
        uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else { //<=iOS6, Use UDID of Device       
            CFUUIDRef uuid = CFUUIDCreate(NULL);
            //uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);- for non- ARC
            uniqueIdentifier = ( NSString*)CFBridgingRelease(CFUUIDCreateString(NULL, uuid));// for ARC
            CFRelease(uuid);
         }
    }
return uniqueIdentifier;
}

——重要提示——

UDID和identifierForVendor是不同的:——

1.) On uninstalling  and reinstalling the app identifierForVendor will change.

2.) The value of identifierForVendor remains the same for all the apps installed from the same vendor on the device.

3.) The value of identifierForVendor also changes for all the apps if any of the app (from same vendor) is reinstalled.

您已经可以使用Apple UDID的替代方案了。gekitz在UIDevice上写了category,它会根据设备mac地址和包标识符生成某种UDID。

你可以在github上找到代码

可以帮助: 使用下面的代码,它将永远是唯一的,除非你擦除(格式)你的设备。

objective - c:

选项1:这将在每次安装时更改

UIDevice *uuid = [NSUUID UUID].UUIDString;

选项2:这将是唯一的每个供应商/开发者苹果帐户

UIDevice *myDevice = [UIDevice currentDevice];
NSString *uuid = [[myDevice identifierForVendor] UUIDString];

斯威夫特5。X:

选项1:这将在每次安装时更改

let uuid = UUID().uuidString

选项2:这将是唯一的每个供应商/开发者苹果帐户

let myDevice = UIDevice.current
let uuid = myDevice.identifierForVendor?.uuidString

也许你可以用:

[UIDevice currentDevice].identifierForVendor.UUIDString

苹果的文档对identifierforvendor的描述如下:

对于运行在同一设备上的来自同一供应商的应用程序,此属性的值是相同的。对于同一设备上来自不同供应商的应用程序,以及不同设备上的应用程序,无论供应商如何,都会返回不同的值。