Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
Forked from joshavant/gist:3355530
Created August 15, 2012 13:51
Show Gist options
  • Save codeswimmer/3360314 to your computer and use it in GitHub Desktop.
Save codeswimmer/3360314 to your computer and use it in GitHub Desktop.
Apple-safe UUID Generation
// requires UICKeyChainStore lib
NSString *uniqueIdentifier;
#if TARGET_IPHONE_SIMULATOR
uniqueIdentifier = @"SIMULATOR";
#else
uniqueIdentifier = [UICKeyChainStore stringForKey:@"UUID" service:@"joshavant"];
if(![uniqueIdentifier length] > 0)
{
// generate a new unique ID
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef stringRef = CFUUIDCreateString (kCFAllocatorDefault,uuidRef);
NSString* newUUID = (__bridge NSString *)stringRef;
[UICKeyChainStore setString:newUUID forKey:@"UUID" service:@"joshavant"];
uniqueIdentifier = newUUID;
CFRelease(stringRef);
CFRelease(uuidRef);
}
#endif
// now uniqueIdentifier is your effective UUID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment