ios - 为 iPhone 生成唯一 ID

标签 ios uuid uniqueidentifier

您好,我正在开发小型 iPhone 应用程序,我想在其中为我的设备生成唯一 ID。我正在使用以下东西:

-(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;
}

所以我在本地测试了这段代码。意味着每次我卸载并再次安装它时,它都会为我创建相同的唯一代码。但是,当我将其推送到应用程序商店时,同一设备上的每次安装都会生成不同的代码。我想为同一设备上的每次安装生成相同的代码。有什么方法可以做到这一点。需要一些帮助。

我想为设备生成一个唯一标识符,即使我多次安装和卸载应用程序,该标识符也与我的设备相同。我使用的是OIS 7.0版本。

谢谢。

最佳答案

identifierForVendor 仅在系统还原后更改,您可以在此处查看我的一些测试:iOS 7 access UUID value in an enterprise application (not for AppStore) 。 如果 iOS 版本低于 ios6,您可以将 id 保存在钥匙串(keychain)中,即使在应用程序卸载后它也会保留

关于ios - 为 iPhone 生成唯一 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25181013/

相关文章:

mysql - 带有 MySQL 的 Entity Framework 6 - UniqueIdentifier 问题

algorithm - 来自类属性的唯一、人类可读的 ID

objective-c - shouldAutorotateToInterfaceOrientation 被多次调用 - 这正常吗?

ios - SwiftUI 无法平移图像

android - 你能在 Ionic 1 上使用 Native Storage 吗?

ios - 在 native iOS设置中更改位置权限时收到通知

node.js - Sequelize UUID 中的意外 token 'export'

MySQL设置默认ID UUID

angularjs - AngularJS 中的 uuid 有何用途?

ios - 替代 [UIDevice currentDevice].identifierForVendor