Tuesday, May 28, 2013

Alternative to iPhone device ID (UDID)

You can get iPhone device ID using this "udid" method and you can download OpenUDID class from https://github.com/ylechelle/OpenUDID 

+ (NSString *)udid

    NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
    static NSString *uuid = nil;
    // try to get the NSUserDefault identifier if exist
    if (uuid == nil) {
        uuid = [standardUserDefault objectForKey:@"UniversalUniqueIdentifier"];
    // if there is not NSUserDefault identifier generate one and store it
    if (uuid == nil) {
        uuid = [self genarateUDID];
        [standardUserDefault setObject:uuid forKey:@"UniversalUniqueIdentifier"];
        [standardUserDefault synchronize];
    return uuid;

+ (NSString *)genarateUDID
    NSString *uniqiPhoneID;

    if (!NSClassFromString(@"ASIdentifierManager")) {
        // This is will run before iOS6 and you can use openUDID, per example...
        uniqiPhoneID = [OpenUDID value];
    if (uniqiPhoneID == nil || [uniqiPhoneID isEqual:[NSNull null]])
        CFUUIDRef uuid = CFUUIDCreate(NULL);
        CFStringRef udidString = CFUUIDCreateString(NULL, uuid);
        uniqiPhoneID = (__bridge NSString *)(udidString);
    return uniqiPhoneID;


No comments:

Post a Comment

Add your comment