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
How to Load Image from Local Path iOS Swift (By Path)
Take Screenshots in the iOS Simulator
How to Set Cornerradius For Only Top-Left and Top-Right Corner of a Uiview
Nsurlsession/Nsurlconnection Http Load Failed on iOS 9
React Native App Works on Debug Mode, But Not Works Release Mode on Ios
Uistackview Hiding/Unhiding Arrangedsubview Issue
Open Facebook Page in Native Facebook iOS App Via Simple Url Sheme Issue
Remove Alpha Channel in an Image
Swift - Integer Conversion to Hours/Minutes/Seconds
Cell Size Not Updating After Changing Flow Layout'S Itemsize
Nsattributedstring Click Event in Uilabel Using Swift
How to Programmatically Scroll Through a Collection View
Passing Data Between View Controllers
Using Auto Layout in Uitableview For Dynamic Cell Layouts & Variable Row Heights
What Is Silent Push Notification? When Does the Device Receive It
Ios 8 Uitableview Separator Inset 0 Not Working