title: CFUUID stored in SSKeychain is null in some devices
body: <p>My published application makes use of the <code>CFUUID</code> and <code>SSKeychain</code> in order to identify the device (and to keep that ID unchanged even if the app is uninstalled and reinstalled)</p>
  
  <p>I save those device ID in the server, and I recently noticed that <strong>some</strong> users have several of those IDs for the same real device. The only explanation I see is that the ID is not being saved or loaded from the Keychain and thus the device generates a new one. The strange thing is that it works fine on some other devices running the same iOS version.</p>
  
  <p>Any ideas on what could be going on?</p>
  
  <p>This is my related code in <code>(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code></p>
  
  <pre><code>NSString* identifier = @"appName";
  NSString* serviceName = @"com.company.appName";
  NSString *retrieveuuid = [SSKeychain passwordForService:serviceName account:identifier];
  if (retrieveuuid == nil) {
      CFUUIDRef theUUID = CFUUIDCreate(NULL);
      CFStringRef string = CFUUIDCreateString(NULL, theUUID);
      CFRelease(theUUID);
      NSString *uuid  = (NSString*) string;
      [SSKeychain setPassword:uuid forService:serviceName account:identifier];
  }
  </code></pre>
  
  <p>EDIT: My guess is that <code>retrieveuuid == nil</code> is not working as expected for some reason. Later in the app I register for push notifications and send the push token to the server together with this CFUUID that I read with the same exact line <code>[SSKeychain passwordForService:serviceName account:identifier]</code> but when it is sent to the server it is not nil (So I can see several CFUUIDs with the same push token).</p>
  
  <p>EDIT 2 to attach more actual code.</p>
  
  <p>AppDelegate.m</p>
  
  <pre><code>NSString* identifier = @"appName";
  NSString* serviceName = @"com.company.appName";
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      //Creating UUID
      NSString *retrieveuuid = [AppDelegate getDeviceId];
      if (retrieveuuid == nil) {
          CFUUIDRef theUUID = CFUUIDCreate(NULL);
          CFStringRef string = CFUUIDCreateString(NULL, theUUID);
          CFRelease(theUUID);
          NSString *uuid  = (NSString*) string;
          [SSKeychain setPassword:uuid forService:serviceName account:identifier];
      }
  
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
       (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
  }
  
  + (NSString*) getDeviceId {
      return [SSKeychain passwordForService:serviceName account:identifier];
  }
  
  - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  {
      NSString *newToken = [deviceToken description];
      newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"&lt;&gt;"]];
      newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
  
      _deviceToken = [[NSString alloc] initWithString:newToken];
  
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
      NSString *user = [prefs objectForKey:@"appNameUsername"];
  
      if(user &amp;&amp; ![user isEqualToString:@""]){
          RestClient *rest = [[RestClient alloc] init];
          rest.delegate = self;
          rest.tag = 2;
          [rest updateToken:newToken ForUsername:user];
          [rest release];
      }
  }
  </code></pre>
  
  <p>RestClient.m</p>
  
  <pre><code>-(void) updateToken:(NSString *)token ForUsername:(NSString *)userName{
      NSArray* info = [NSArray arrayWithObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                                 userName, @"Username",
                                                 token, @"TokenNo",
                                                 [[UIDevice currentDevice].model hasPrefix:@"iPad"] ? @"iPad" : @"iPhone", @"Device",
                                                 [UIDevice currentDevice].systemVersion, @"OSVersion",
                                                 [AppDelegate getDeviceId], @"DeviceID",
                                                 @"updateToken", @"CMD",
                                                 nil]];
      [self doAction:info];
  }
  </code></pre>
  
  <p>The doAction method just sends the data to the server and then callback the delegate, that part works fine. I can see on the server the logs of receiving this command:</p>
  
  <pre><code>"JSONCMD":"[
  {   "TokenNo" : "f0d3aa21758350333b7e6315c38_EDIT_257c1838f49c43049f8380ec1ff63", 
      "AppVersion" : "1.0.4",
      "Username" : "user@server.com", 
      "CMD" : "updateToken", 
      "OSVersion" : "7.0.4", 
      "DeviceID" : "9B794E11-6EF7-470C-B319-5A9FCCDAFD2B", 
      "Device" : "iPhone"
  }
  ]  
  </code></pre>
  
  <p>I see 2 possible candidates causing the strange behaviour, the <code>NSStrings</code> in the controller body and the static <code>getDevice</code> method. However, I don't see how this could work in many devices but fail in others.</p>