是否有UDID的替代方案?我的应用程序将不会在App Store中发布,因为我使用企业发布。因此,是否有任何替代方案?我尝试过广告标识符、OpenUDID、UIID和SecureUDID。但是如果手机被重置,那么我将得到一个新的UDID。非常感谢任何帮助。
是否有UDID的替代方案?我的应用程序将不会在App Store中发布,因为我使用企业发布。因此,是否有任何替代方案?我尝试过广告标识符、OpenUDID、UIID和SecureUDID。但是如果手机被重置,那么我将得到一个新的UDID。非常感谢任何帮助。
如果您的iOS版本高于6.0,您可以使用identifierForVendor
或者CFUUIDRef
。
-(NSString*)uniqID
{
NSString* uniqueIdentifier = nil;
if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) {
// iOS 6+
uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// before iOS 6, so just generate an identifier and store it
uniqueIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"identifierForVendor"];
if( !uniqueIdentifier ) {
CFUUIDRef uuid = CFUUIDCreate(NULL);
uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
[[NSUserDefaults standardUserDefaults] setObject:uniqueIdentifier forKey:@"identifierForVendor"];
}
}
return uniqueIdentifier;
}//
更新
如Leon Lucardie
所评论,他是正确的。
identifierForVendor在应用程序卸载/重新安装后将更改。参见此处。在iOS设备上安装应用程序(或来自同一供应商的另一个应用程序)时,此属性中的值保持不变。当用户从设备中删除该供应商的所有应用程序并随后重新安装其中一个或多个应用程序时,该值会更改。
identifierForVendor
在应用卸载/重新安装后会更改。请参见此处当该应用程序(或同一供应商的另一个应用程序)安装在iOS设备上时,该属性中的值保持不变。但是,如果用户删除该供应商的所有应用程序,然后随后重新安装其中一个或多个应用程序,则该值将更改。 - Leon Lucardie尝试了所有可能的替代方案后,广告标识符是最好的选择。我测试过,即使手机重置,它仍然保持不变。如果用户在设置中关闭它,那么我们会得到一个空值。除了这个小问题,这是迄今为止最好的替代方案。如果我找到其他更好的替代方案,我会更新的。
非常简单,只需要使用以下代码:
-(NSString *)getUID{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
// This is will run if it is iOS6 and above
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// This is will run before iOS6 and you can use openUDID or other
// method to generate an identifier
return [OpenUDID value];
}
}
如您所知,如果您计划支持iOS 5,则应使用OpenUDID(即使在iOS 5上,Apple也限制读取UDID)。 有些答案可能会被苹果拒绝(我的代码已获得多款应用的批准)。
请注意,如果用户删除了该应用程序(或所有供应商应用程序(如果有多个))并重新安装,则identifierForVendor将更改。
您可以在iOS 6+上使用Swift 2.2版本。
var uniqueIdentifier: NSString!
uniqueIdentifier = UIDevice.currentDevice().identifierForVendor?.UUIDString
以下 Ole 的博客文章应该会有所帮助:
iOS 5: http://oleb.net/blog/2011/09/how-to-replace-the-udid/ iOS 6+: http://oleb.net/blog/2012/09/udid-apis-in-ios-6/