title: iphone registration and authentication pattern
body: <p>I am looking for a stable (and Apple compliant) registration and authentication design pattern between an iphone device and a server. Ideally the registration and authentication would not involve the user and be a background process. </p>
  
  <p>So far I've found 3 primitives for doing components of this:</p>
  
  <ol>
  <li>UDID</li>
  <li>UUID</li>
  <li>SBFormattedPhoneNumber</li>
  </ol>
  
  <p><strong>UDID method</strong></p>
  
  <pre><code> [[UIDevice currentDevice] uniqueIdentifier]
  
      where @property (nonatomic, readonly, retain) NSString *uniqueIdentifier
  </code></pre>
  
  <p>uniqueIdentifier is a string unique to each device based on various hardware details. (read-only)</p>
  
  <p>A unique device identifier is a hash value composed from various hardware identifiers such as the device’s serial number. It is guaranteed to be unique for every device but cannot publically be tied to a user account.  You can use it, for example, to store high scores for a game in a central server or to control access to registered products. The unique device identifier is sometimes referred to by its abbreviation UDID. We can get UDID from iTunes manually for checking </p>
  
  <p>Not sure what "<em>cannot publically be tied to a user account"</em> means. </p>
  
  <p><strong>UUID method</strong></p>
  
  <pre><code>NSString *uuid = nil;
  CFUUID theUUID = CFUUIDCreate(kCFAllocatorDefault);
  if (theUUID) {
    uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID);
    CFRelease(theUUID);
  }
  </code></pre>
  
  <p>CFUUIDCreate creates a Universally Unique Identifier (UUID) object. UUID object is different every time CFUUIDCreate is invoked. Therefore we need to generate it on first launch and then save it to your preferences using NSUserDefaults. The downside to this is that if the app is deleted and reinstalled or if the device is restored from backup, you'll lose the saved UUID and things won't be recognized as from the same device.</p>
  
  <p><strong>SBFormattedPhoneNumber</strong></p>
  
  <pre><code>NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@”SBFormattedPhoneNumber”];
  NSLog(@”Phone Number: %@”, num);
  </code></pre>
  
  <p>The number returned by this code snippit is the number that is set up in iTunes for the device. If you didn’t enter the iPhone’s in iTunes at device activation, or perhaps [as in my case] if the default value wasn’t the iPhone’s number and you clicked OK anyway, such that iTunes doesn’t list the phone number when your iPhone is plugged in, this code will return a null string.</p>
  
  <p>"For security reasons, iPhone OS restricts an application (including its preferences and data) to a unique location in the file system. This restriction is part of the security feature known as the application's "sandbox." The sandbox is a set of fine-grained controls limiting an application's access to files, preferences, network resources, hardware, and so on."</p>
  
  <p>The device's phone number is not available within your application's container. You will need to revise your application to read only within your directory container and resubmit your binary to iTunes Connect in order for your application to be reconsidered for the App Store.</p>
  
  <p>thank you in advance for your help. </p>
  
  <p>peyman</p>