Skip to content

Instantly share code, notes, and snippets.

@shayanb
Forked from sag333ar/getUDID.m
Last active August 29, 2015 14:13
Show Gist options
  • Save shayanb/9d482ffe86827e55b190 to your computer and use it in GitHub Desktop.
Save shayanb/9d482ffe86827e55b190 to your computer and use it in GitHub Desktop.
- (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