检索iOS设备标识符

aum*_*ets 5 iphone uniqueidentifier ios

有没有办法在iOS SDK中获取iOS设备标识符?我想访问管理器 - 设备部分中的Xcode所呈现的标识符,例如:21xb1fxef5x2052xec31x3xd3x48ex5e437xe593

lup*_*tus 12

看起来你仍然可以在iOS 6下访问UDID,但是自iOS 5.0以来它已被弃用,你不应该使用它(无论如何你都会收到警告)

[UIDevice currentDevice].uniqueIdentifier
Run Code Online (Sandbox Code Playgroud)

如果您需要唯一标识符,则应使用:

[UIDevice currentDevice].identifierForVendor
Run Code Online (Sandbox Code Playgroud)

或者如果它与某种广告有关,那么:

// from  AdSupport.framework
[ASIdentifierManager sharedManager].advertisingIdentifier
Run Code Online (Sandbox Code Playgroud)

然而,这两个新属性仅在iOS> = 6.0下可用,而且advertisingIdentifier也不是唯一的(我从中获得了许多重复).

如果你不支持iOS <6,我想你可以做类似的事情:

UIDevice *device = [UIDevice currentDevice];
NSString *ident = nil;
if ([device respondsToSelector:SEL(identifierForVendor)]) {
    ident = [device.identifierForVendor UUIDString];
} else {
    ident = device.uniqueIdentifier;
}
Run Code Online (Sandbox Code Playgroud)

但我不确定苹果将在审核期间对此做出如何回应.

您还可以使用某些第三方解决方案,如openUDIDsecureUDID.不推荐使用开放和安全的UDID - 使用供应商/广告的标识符.


更新

一种可能性是使用MAC地址作为唯一散列的基础,例如,您可以使用ODIN1中的代码- source就在这里

从iOS7开始,MAC地址不再可用.(人们可以读它,但它总是相同的虚拟地址02:00:00:00:00:00).


Nic*_*ull 7

来自Apple文档:

基于各种硬件详细信息的每个设备唯一的字母数字字符串.(只读)(在iOS 5.0中不推荐使用.请根据需要使用此类的identifierForVendor属性或ASIdentifierManager类的advertisingIdentifier属性,或使用NSUUID类的UUID方法创建UUID并将其写入用户默认数据库.)