问题描述:

How to create unique Alphanumeric id from iPhone whenever i required? It must be distinct because it is sharable to all iphone.

网友答案:

I use this code in my Utils class to generate the UUID:

+ (NSString *)newUUID
{
    CFUUIDRef uuid = CFUUIDCreate(NULL);
    CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
    NSString *result = [[NSString alloc] initWithFormat:@"%@", [(NSString *)uuidStr lowercaseString]];
    CFRelease(uuidStr);
    CFRelease(uuid);
    return result;    
}

The method starts with new, so make sure to release the string when you are done with it, or autorelease it.

网友答案:

Take a look at CFUUID. A UUID can be expected to be unique across space and time (give or take a few caveats.)

相关阅读:
Top