问题
I have been using the following method for around a month with no problem. The device ID remained the same even after uninstalls of the app. Recently I noticed that my device ID changed. I have been doing a lot of builds of the app recently on Xcode6. Could this be a cause? I wish I knew exactly when it changed. It caught me by surprise. Do I have anything to worry about when the app goes on the app store? Maybe this is just an Xcode build problem? I am just looking for a simple way to guarantee a unique device ID. I would use advertisingIdentifer but I hear using it for purpose other then advertisements will get rejected by app store. Here is the code:
+ (NSString *)getUserID
{
NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *retrieveuuid = [SSKeychain passwordForService:Appname account:@"user"];
if(retrieveuuid == NULL)
{
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
retrieveuuid = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
CFRelease(newUniqueId);
[SSKeychain setPassword:retrieveuuid forService:Appname account:@"user"];
}
NSLog(@"%@", retrieveuuid);
return retrieveuuid;
}
回答1:
The unique device id does not persist This has been asked many times before and you should find some good info on here. A quick Google search brings up the following.
https://stackoverflow.com/search?q=iOS+UDID+replacement
Persistent UDID equivalent for iOS 7?
UIDevice uniqueIdentifier Deprecated - What To Do Now?
iOS unique user identifier
general advice is to use CFUUID
to create your own UUID
, then persist it in the keychain
来源:https://stackoverflow.com/questions/27276645/why-did-my-unique-device-id-change