How to Get a Unique Device Id in Swift

How to get a unique device ID in Swift?

You can use this (Swift 3):

UIDevice.current.identifierForVendor!.uuidString

For older versions:

UIDevice.currentDevice().identifierForVendor

or if you want a string:

UIDevice.currentDevice().identifierForVendor!.UUIDString



There is no longer a way to uniquely identify a device after the user uninstalled the app(s). The documentation says:

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.



You may also want to read this article by Mattt Thompson for more details:

http://nshipster.com/uuid-udid-unique-identifier/

Update for Swift 4.1, you will need to use:

UIDevice.current.identifierForVendor?.uuidString

How to get UDID Programmatically in Swift on iOS

identifierForVendor is not the device UUID. You cannot programmatically access the device UUID. The only ID you are supposed to use to identify a device is identifierForVendor, which intentionally can change if the user uninstalls all of your apps. There is, intentionally, no fixed-to-the-device ID that you are permitted to access.

How do I get device id in the Apple Cocoa application?

You can get the Hardware UUID with IOKit

func hardwareUUID() -> String?
{
let matchingDict = IOServiceMatching("IOPlatformExpertDevice")
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict)
defer{ IOObjectRelease(platformExpert) }

guard platformExpert != 0 else { return nil }
return IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? String
}


Related Topics



Leave a reply



Submit