[Objective-C] UUID on iOS 5

Hi all,
today a simple way to get device UID from code because in iOS5, function uniqueIdentifier was deprecated.

Src: UIDevice/uniqueIdentifier

This is my way, using CFUUID class (reference here), but there is surely a better method to do this.
This method is valid until user not delete app from device and reinstall!:


– Create a new UUID
– Store it to UserDefault
– Get it from UserDefault

+ (NSString*) GetUID {
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  return [(NSString *)string autorelease];

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults) {
  [standardUserDefaults setObject:[YourClass GetUID] forKey:@"UID"];
  [standardUserDefaults synchronize];

+ (NSString*) UID {
  NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
  if (standardUserDefaults) return [standardUserDefaults objectForKey:@"UID"];

Make sure you’re saving only ONE time uid to local storage. GetUID method, create a new one every time.


If you want an easy library to include in your projects, you can download version 0.1 from zip.


How to use?

:: Add in your project framework the library (libAPUUID.a file)
:: Add APUUID.h in your project.

To get UUID:

#import "APUUID.h"
NSLog(@"%@", [APUUID uniqueIdentifier]);

easy way. It works on iOS >= 3.0. On Device and Simulator.

Soon on github…

Hope this helps.