![](/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.