您好,我正在开发小型 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/