How to get Device UDID in programmatically in iOS7

2019-01-13 05:00发布

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 device UDID. The UDID String changing when I delete the app and the reinstall means the UDID was getting different one.

标签: iphone udid
10条回答
Juvenile、少年°
2楼-- · 2019-01-13 05:25

Swift 2.2+ proper way to get UUID:

if let UUID = UIDevice.currentDevice().identifierForVendor {
  print("UUID: \(UUID.UUIDString)")
}
查看更多
趁早两清
3楼-- · 2019-01-13 05:26

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;
    }
}
查看更多
来,给爷笑一个
4楼-- · 2019-01-13 05:27

In Swift you can get the device UUID like this

let uuid = UIDevice.currentDevice().identifierForVendor.UUIDString
println(uuid)
查看更多
Summer. ? 凉城
5楼-- · 2019-01-13 05:29

In Swift 3.0:

UIDevice.current.identifierForVendor!.uuidString

old version

UIDevice.currentDevice().identifierForVendor

you want a string:

UIDevice.currentDevice().identifierForVendor!.UUIDString
查看更多
登录 后发表回答