![](/img/trans.png)
[英]identifierForVendor changed when updating new version of app on older version. Why?
[英]Why does iOS get a new identifierForVendor when app updates?
每次我的应用程序从App Store更新时,由于某种原因,少数用户会获得新的identifierForVendor 。 我的用户没有注册或登录。 它们都是匿名的,因此我需要通过供应商ID将它们分开。
我认为在某些设备上可能没有足够的空间,导致应用程序被删除并重新安装,但事实并非如此,因为在上一次更新中我的一个朋友有超过2GB的空闲空间。
我知道删除并重新安装应用程序的用户更改了identifierForVendor 。 但这不是这里的情况,因为应用程序刚刚更新。
问题是什么? 奇怪的是,尚未发现开发团队设备。 或者仍然有用户在无数的应用更新,操作系统更新等之后没有遇到此错误。这只发生在一小部分用户身上。 所有用户都是iOS7 +,它适用于不同的设备型号和iOS版本。
我使用此代码获取其ID:
static let DeviceId = UIDevice.currentDevice().identifierForVendor.UUIDString
然后我将它们保存到NSUserDefaults中:
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "User" + DeviceId)
NSUserDefaults.standardUserDefaults().synchronize()
然后我会在每次新登录时检查用户是否存在:
static func doesUserExist() -> Bool {
var userDefaultValue: AnyObject? = NSUserDefaults.standardUserDefaults().valueForKey("User" + DeviceId)
if defaultValue == true {
println("Userdefaults already has this guy, moving on")
FirstTime = false
return true
} else {
println("First time in the app!")
FirstTime = true
return false
}
}
如果用户确实存在,则启动登录过程。 如果用户不存在,则向他们显示注册过程。 我使用Parse.com作为后端,deviceID用作用户名。 当少量用户遇到此错误时,我会看到一个新用户名和一个新帐户。
在5月到7月期间从应用商店更新应用时,存在影响identifierForVendor计算的错误。 Apple声称他们已经解决了这个问题并推动另一次更新应该在关键日期之前恢复原始值。 参考: https : //openradar.appspot.com/22677034
请注意,一些用户甚至在7月之后的几周内仍然观察到此问题。 所以仍有可能某些bug仍然存在,或者它可能在将来的任何时候重新出现。 因此,如果您将此数据用作加密的一部分,最好将其保存到钥匙串中。
将vendorID保存在KeyChain中,该ID将在删除或任何更新后保留。
-(NSString *)getUniqueDeviceIdentifierAsString
{
NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
if (strApplicationUUID == nil)
{
strApplicationUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
}
return strApplicationUUID;
}
免责声明:我刚才接受了其他一些SO代码的答案,
所以我不记得有谁赞美,但最后不是我
@Jonny找到了消息来源
我很困惑为什么你首先将IFV保存到NSUserDefaults然后检查是否存在该密钥。 我想你应该...
1)首先检查NSUserDefaults以查看您创建的IFV密钥是否存在
2)如果NSUserDefaults密钥确实存在,那么用它做得很好,这个用户的配置文件已经存在
3)如果密钥不存在,请获取IFV并将其保存到NSUserDefaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults valueForKey:@"IFV"]) {
//this user already exists, do what you need to do next with IFV
}
else{
//this is their first time using the app
NSString *ifvString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[defaults setValue:ifvString forKey:@"IFV"];
//do what you need to do next with IFV
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.