Search code examples
iosobjective-cuuid

UUID v1 Objective-C implementation


I want to implement UUID v1 in my iOS App. I know that it is composed of Mac Address and timestamp as described in http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28MAC_address.29

Is there any objective-c implementation for this V1, based on CFUUID functions ?

I already have the mac address and the timestamp.

The UUID v1 description at Wikipedia : "The original (version 1) generation scheme for UUIDs was to concatenate the UUID version with the MAC address of the computer that is generating the UUID, and with the number of 100-nanosecond intervals since the adoption of the Gregorian calendar in the West"

It is also specified at http://www.ietf.org/rfc/rfc4122.txt , but it seems that it will need time to implement it.

I have found this link : http://www.famkruithof.net/guid-uuid-timebased.html who have a simple explanation for the steps to create a v1 UUID. Is there any existing implementation, before I implement it by my self?


Solution

  • I thinks it is common behavior to use framework functions. And that is use CFUUID. For example:

    +(NSString*)get {
        NSString *deviceID = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceID"];
        if (!deviceID) {
            CFUUIDRef theUUID = CFUUIDCreate(NULL);
            CFStringRef string = CFUUIDCreateString(NULL, theUUID);
            CFRelease(theUUID);
            deviceID = (NSString*)string;
            [[NSUserDefaults standardUserDefaults] setValue:deviceID forKey:@"DeviceID"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    
        return deviceID;
    }