How to Get Unique Id in iOS Device

How to get unique id in iOS device?

You can no longer get a unique ID per device. identifierForVendor is the best you're going to get. Apple has systematically disabled identifying a specific device so that users' IDs can't be passed around by marketers.

To get the identifier ID as a string, you can use

let deviceId = UIDevice.current.identifierForVendor?.uuidString

UPDATE

If you want a universal ID then you have the option to use advertisingIdentifier. However, if the user has limited ad tracking in their device settings then this value will simply return all zeroes.

import AdSupport

let identifierManager = ASIdentifierManager.shared()
if identifierManager.isAdvertisingTrackingEnabled {
let deviceId = identifierManager.advertisingIdentifier.uuidString
}

N.B. Apple recommends that this code only be used by companies building advertisement frameworks, rather than the app developers themselves. If you use this within your code for non-ad-related purposes then prepare to have your app rejected.

How to fetch unique id for iPhone device

You can save str_udid object into the Keychain. Here is the link about how to do that: https://github.com/kishikawakatsumi/KeychainAccess

It will not remove even if you have deleted your application from the device.

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 generate Unique ID of device for iPhone/iPad using Objective-c

Yes, UDID is deprecated; we are not allowed to get UDID due to user privacy purposes. Apple does not allow to get any identifiers that uniquely identifies a device, such as IMEI, MAC address, UDID etc.

UUID is the best way to go as of now. But that would be unique for each vendor. You are not assured that it will be unique each time you get the UUID string. Best bet is to store the UUID string to phone's Keychain and retrieve it when needed, with a catch. When you factory-reset your phone, the keychain items would be erased. This limitation should be kept in mind.


UPDATE - IN IOS 10.3 BETA'S:

It seems that Apple has made some changes to how Keychain works in iOS 10.3+. Keychain items stored in the Keychain will be deleted when the all the apps from the specific vendor are uninstalled. According to Apple, the residence of sensitive information of an app even after the app is gone from the device may lead to security risks, so they decided to forbid this kind of behavior.

Developers relying on Keychain storage even after an uninstall for their apps can make use of this WORKAROUND to continue with the intended functionality. According to this workaround, any app can access the information stored in that specific Keychain Access Group, so it is recommended that adding an extra layer of encryption to your data will protect it with even more security, although keychain encrypts items by default.



UPDATE - IOS 10.3.3 (STABLE):
It seems that the keychain items deletion was a BUG in early betas of iOS 10.3.3 and was fixed later in the stable release. This might have been caused during betas since strange things can happen during that phase. It should be no problem to use Keychain hereafter.

Can I get an unique and permanent device identifier on a Flutter app (iOS)?

Finally I've decided to use the "identifierForVendor" because it seems the more appropriate for the app context.



Related Topics



Leave a reply



Submit