4

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;
}
user4233467
  • 169
  • 1
  • 2
  • 8
  • 1
    As a sidenote: a better choice to use would be `-[UIDevice identifierForVendor]`. See [the docs](https://developer.apple.com/library/iOS/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/instp/UIDevice/identifierForVendor). – ravron Dec 03 '14 at 16:28
  • 1
    probably you have restarted your device. – holex Dec 03 '14 at 16:41
  • @Riley to my knowledge the identifierForVendor will change if they uninstall all of my apps. I don't want the id to ever change when they uninstall my app. – user4233467 Dec 03 '14 at 19:43
  • @user4233467 Yes, I believe that is true. I'm not sure that what you want exists (I'm not sure it doesn't exist, either - I just don't know). – ravron Dec 05 '14 at 03:49

1 Answers1

6

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

Community
  • 1
  • 1
JSA986
  • 5,870
  • 9
  • 45
  • 91