Created
November 28, 2011 13:56
-
-
Save gonecoding/1400481 to your computer and use it in GitHub Desktop.
Persistent Unique Identifier (GUID, UUID, UDID)
This file contains 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
/* | |
UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) | |
or IIDs (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is | |
made unique over both space and time by combining a value unique to the computer on which | |
it was generated—usually the Ethernet hardware address—and a value representing the number | |
of 100-nanosecond intervals since October 15, 1582 at 00:00:00. | |
*/ | |
#define AppDelegateDefaultsKeyPersistentUniqueIdentifier @"AppDelegateDefaultsKeyPersistentUniqueIdentifier" | |
- (NSString*)persistentUniqueIdentifier | |
{ | |
// try to read unique identifier from user defaults | |
NSString* result = [[NSUserDefaults standardUserDefaults] objectForKey:AppDelegateDefaultsKeyPersistentUniqueIdentifier]; | |
if( result == nil ) | |
{ | |
// create new unique identifier | |
CFUUIDRef uuid = CFUUIDCreate( nil ); | |
result = [(NSString*)CFUUIDCreateString( nil, uuid ) autorelease]; | |
CFRelease( uuid ); | |
// store new unique identifier in user defaults and synchronize them | |
[[NSUserDefaults standardUserDefaults] setObject:result forKey:AppDelegateDefaultsKeyPersistentUniqueIdentifier]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment