rustyshelf rustyshelf - 1 year ago 87
iOS Question

How to create a GUID/UUID using the iPhone SDK

I want to be able to create a GUID/UUID on the iPhone and iPad.

The intention is to be able to create keys for distributed data that are all unique. Is there a way to do this with the iOS SDK?

Answer Source
[[UIDevice currentDevice] uniqueIdentifier]

Returns the Unique ID of your iPhone.

EDIT: -[UIDevice uniqueIdentifier] is now deprecated and apps are being rejected from the App Store for using it. The method below is now the preferred approach.

If you need to create several UUID, just use this method (with ARC):

+ (NSString *)GetUUID
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  return (__bridge NSString *)string;

EDIT: Jan, 29 2014: If you're targeting iOS 6 or later, you can now use the much simpler method:

NSString *UUID = [[NSUUID UUID] UUIDString];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download