How to get Device UDID in programmatically in iOS7?

前端 未结 10 2211
梦谈多话
梦谈多话 2020-12-04 18:33

How to get device UDID in programatically in iOS7.[[UIDevice currentDevice] uniqueIdentifier] I was used this code This is deprecated iOS7. how to get the devic

相关标签:
10条回答
  • 2020-12-04 18:45

    In Swift you can get the device UUID like this

    let uuid = UIDevice.currentDevice().identifierForVendor.UUIDString
    println(uuid)
    
    0 讨论(0)
  • 2020-12-04 18:47

    It's work 100% to all the version

    other best option recommend by apple use ASIdentifierManager Class Reference

    ios7-app-backward-compatible-with-ios5-regarding-unique-identifier

    this link tell you how to handle and use custom framework

    uidevice-uniqueidentifier-property-is-deprecated-what-now

    iOS 9

    NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
    NSLog(@"%@",uuid);
    NSLog(@"%@",[uuid UUIDString]);
    

    or

    it support only ios 6.0 and above

    code to use [[[UIDevice currentDevice] identifierForVendor] UUIDString];

    NSUUID *deviceId;
    #if TARGET_IPHONE_SIMULATOR
    deviceId = [NSUUID initWithUUIDString:@"UUID-STRING-VALUE"];
    #else
    deviceId = [UIDevice currentDevice].identifierForVendor;
    #endif
    

    ios 5 to use like

     if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
        // This is will run if it is iOS6
        return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
       // This is will run before iOS6 and you can use openUDID or other 
       // method to generate an identifier
    }
    
    0 讨论(0)
  • 2020-12-04 18:49

    UDID is no longer available in iOS 6+ due to security / privacy reasons. Instead, use identifierForVendor or advertisingIdentifier.

    Please go through this link.

       NSString* uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
       NSLog(@"UDID:: %@", uniqueIdentifier);
    

    UPDATE for iOS 8+

    + (NSString *)deviceUUID
    {
        if([[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]])
            return [[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]];
    
        @autoreleasepool {
    
            CFUUIDRef uuidReference = CFUUIDCreate(nil);
            CFStringRef stringReference = CFUUIDCreateString(nil, uuidReference);
            NSString *uuidString = (__bridge NSString *)(stringReference);
            [[NSUserDefaults standardUserDefaults] setObject:uuidString forKey:[[NSBundle mainBundle] bundleIdentifier]];
            [[NSUserDefaults standardUserDefaults] synchronize];
            CFRelease(uuidReference);
            CFRelease(stringReference);
            return uuidString;
        }
    }
    
    0 讨论(0)
  • 2020-12-04 18:49

    Swift 2.2+ proper way to get UUID:

    if let UUID = UIDevice.currentDevice().identifierForVendor {
      print("UUID: \(UUID.UUIDString)")
    }
    
    0 讨论(0)
  • 2020-12-04 18:52

    Have 2 solutions:

    • You can use identifierForVendor after that store them to keychain and use later. Because value of keychain will not changed when re-install app.
    • You can try OpenUDID
    0 讨论(0)
  • 2020-12-04 18:53

    For getting UUID in Swift 3.0:

    let UUIDValue = UIDevice.current.identifierForVendor!.uuidString
    
    0 讨论(0)
提交回复
热议问题