Tag Archives: UUID

Create a Universally Unique IDentifier

Problem: How to get a unique device identifier (i.e. to implement InApp purchasing) without using UDID, banned by Apple.
Solution: In iOS6 we can use identifierForVendor. In prior versions we will use CFUUIDRef. Note that in this case every call of CFUUIDRef creates a new UUID. It is necessary to save the UUID in the device keychain to make it unique.
Read also: Universally Unique IDentifier in iOS5 by Marek Bell
[objc]
+ (NSString *)createLocalUUID {

NSString *localIdentifier;

if ([[UIDevice currentDevice] respondsToSelector:NSSelectorFromString(@”identifierForVendor”)])
// iOS version >= 6
localIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
else {
// iOS version < 6 CFUUIDRef uuidRef = CFUUIDCreate(NULL); CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); CFRelease(uuidRef); localIdentifier = [NSString stringWithString:(__bridge NSString *)uuidStringRef]; CFRelease(uuidStringRef); } return localIdentifier; } [/objc]