Monday, April 11, 2011

How to create a GUID/UUID using the iPhone SDK

I want to be able to create a GUID/UUID on the iPhone but I can't see any way to do it.

The intention is to be able to create keys for distributed data, that are all unique. Do I need some third-party code or is there a built in way to do this in the SDK?

I have tried Googling it, but I could find anything.

From stackoverflow
  • If you want a unique identifier for the particular iPhone you're running on, you can run

    NSString *uniqueIdentifier = [[UIDevice currentDevice] uniqueIdentifier];
    

    You can then use that as a replacement for a MAC address in any of the standard GUID/UUID generation algorithms.

  • Reviewing the Apple Developer documentation I found the CFUUID object is available on the iPhone OS 2.0 and later.

    rustyshelf : that's exactly what I was after, thanks
    bentford : I could really use an example, like below...
  • [[UIDevice currentDevice] uniqueIdentifier]
    

    Returns the Unique ID of your iPhone.

    If you need to create several UUID, just use this method:

    + (NSString *)GetUUID
    {
      CFUUIDRef theUUID = CFUUIDCreate(NULL);
      CFStringRef string = CFUUIDCreateString(NULL, theUUID);
      CFRelease(theUUID);
      return [(NSString *)string autorelease];
    }
    
  • The simplest technique is to use NSString *uuid = [[NSProcessInfo processInfo] globallyUniqueString]. See the NSProcessInfo class reference.

  • Hi, I am looking for a way to extract my iPhone (OS v3.0) UUID without using iTunes. I tried "UUID Revealer" from Cydia Store but that is not working on my system. I could SSH with WinSCP and I have a Terminal Program Installed. Any chances using one of those tools (or another one) to bring to light my UUID? Thanks

    Toby Allen : hi Eddie - bit late now, but you should ask a question rather than adding an answer to someone elses question.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.