Using the UUID, sometimes constant and sometimes not

Hi there,

I'm working on an app that uses the UUID to create a Machine ID that can be compared to a key to allow use of the app. It was working great for a bit especially on the iPhone 7 I could uninstall and reintall the app and the ID would remain the same. However on the iPad and a few older iPhones the ID would change everytime there was an install or update.


After some searching it seemed that it is normal for the UUID to change when installing/updating the app but I'm not sure of why it would stay the same in some cases and change in others.


Would it be better to put the generated ID on the keychain on the first install so it would be consistent?


This is the line of code I'm using to get the UUID (Swift):

UIDevice.current.identifierForVendor!.uuidString


Thanks in advance.

Replies

You should better check the documentation of `identifierForVendor`.


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. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.