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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…