In iOS versions previous to 7.0 getting the MAC address of device was possible. But with new iOS version it has been disabled for the apps to access MAC address of the device.
When it is accessed or requested on current version of iOS it always returns 02:00:00:00:00:00. This has been implemented by apple because of privacy concerns. If your app needs to uniquely identify a device, apple recommends to use UDID/ UUID instead of MAC. In swift we can use
UIDevice.current.identifierForVendor Which as per apple documentation says that, The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.
UIDevice.current.identifierForVendor?.uuidString – returns a string value for the UUID.
We can use them in our application like
override func viewDidLoad() {
super.viewDidLoad()
print(UIDevice.current.identifierForVendor)
print(UIDevice.current.identifierForVendor?.uuidString)
}
When run on an iOS 12.0 simulator on iPhone 7 Plus, it gives the following result
Optional(1E52E5F9-9385-4269-A2CA-A0B9063DCBA5)
Optional("1E52E5F9-9385-4269-A2CA-A0B9063DCBA5