2

I have created a function to get UUID

func deviceUUID() -> String {
    return UIDevice.currentDevice().identifierForVendor?.UUIDString ?? ""
}

But the problem is that when ever I uninstall the app from same device and re-install it. I am getting a totally new UUIDString. If this the default behaviour then can I get previous UUID somehow ? because I have UUID as user ID in our server.

I do have a solution in my mind but I do not know that will it work or not so please guide me on this.

Lets say I get the ID first time and save it in keychains. When user reinstall the app I get the ID from keychains. Is this possible ?

Byte
  • 629
  • 2
  • 11
  • 29

1 Answers1

2

This correct behavior as described in UIDevice documentation.

If you want to store some identifier that is persisted when the app is uninstalled you should save a unique value in the keychain.

Just be aware that even these will not be 100% stored, the user can delete then if he/she has knowledge of the keychain or the device is wiped.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • You can use apple API for unique token generateToken(completionHandler:) . NOTE - The app you use to generate the token must be associated with your developer account; otherwise, the generation request fails – Himanshu Sraswat Sep 13 '18 at 09:48