-
-
Save codeswimmer/3360314 to your computer and use it in GitHub Desktop.
Apple-safe UUID Generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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