Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Last active December 28, 2015 09:49
Show Gist options
  • Save sag333ar/7482046 to your computer and use it in GitHub Desktop.
Save sag333ar/7482046 to your computer and use it in GitHub Desktop.
Get the UDID of the current iOS device.
- (NSString*)UDID {
NSString *uuidString = nil;
// get os version
NSUInteger currentOSVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] integerValue];
if(currentOSVersion <= 5) {
if([[NSUserDefaults standardUserDefaults] valueForKey:@"udid"]) {
uuidString = [[NSUserDefaults standardDefaults] valueForKey:@"udid"];
} else {
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(NULL,uuidRef));
CFRelease(uuidRef);
[[NSUserDefaults standardUserDefaults] setObject:uuidString ForKey:@"udid"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
return uuidString;
} else {
return [UIDevice identifierForVendor];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment