How to generate Unique ID of device for iPhone/iPad using Swift?


UDID(Unique Device Identifier) − A sequence of 40 hexadecimal characters that uniquely identify an iOS device.

Since from iOS 5, Apple has deprecated the UIDevice unique identifier, that means the traditional way of getting the unique id. Apple removed the truly unique identifier and introduced an identifier for each vendor i.e UUID that's the same for all apps for a given developer for each user, but varies between developers and between devices.

Apple has defined an instance property identifier for the vendor, which is an alphanumeric string that uniquely identifies a device to the app’s vendor.

You can read more about it here: https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor

So we will see how we can get, Copy the below code in viewDidLoad method,

override func viewDidLoad() {
   super.viewDidLoad()
   guard let deviceID = UIDevice.current.identifierForVendor?.uuidString else {
      return
   }
   print(deviceID) // 7ABAB8B5-E805-437F-9D6C-5448BB19AEA5
}

Updated on: 30-Aug-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements