
Photo courtesy of http://www.talkandroid.com
The fact that Apple deprecated the use of UDID’s as an identifier for developers in iOS 5 is nothing new. There have been many privacy concerns related to the use of a users UDID by developers, but I won’t get into that. Till now, developers could still access a users UDID, since the API is only deprecated and not fully removed. After the recent Path privacy fiasco, Apple has felt the heat and required app developers to ask for user permission before accessing just about any user data, including UDID.
The good news is there is a very simple alternative to using a users UDID and it’s called UUID (Universally Unique Identifier). UUID was standardized by the Open Software Foundation (OSF) and is said to be “practially unique” rather than “guaranteed unique”. But that’s not something you need to worry about. The Wikipedia page for UUID states:
“… one’s annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate. In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%.”
The even better news is generating a UUID in iOS is extremely simple thanks to Core Foundations CFUUID class. Here’s how:
- (NSString *)uuid
{
// Creates a Universally Unique Identifier (UUID) object.
CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
// Returns the string representation of a specified CFUUID object.
NSString *uuid = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);
CFRelease(uuidObject);
return [uuid autorelease];
}
Note: With ARC you need to use __bridge when casting from CFStringRef to NSString *.
That’s all the code you need to replace your use of UDID’s.
Please share any comments or suggestions below!
1 Comment