fabiocaccamo / FCUUID

:iphone: :id:  iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.
MIT License
1.61k stars 226 forks source link

duplicated uuidForDevice when restoring from iCloud #32

Closed juangz closed 2 years ago

juangz commented 2 years ago

Hey @fabiocaccamo, I'm having an issue when restoring a device using iCloud.

So, we are using uuidForDevice to have a unique id per user per device, but we are facing some issues when people are cloning their devices and as the uuidForDevice is the same (they do a full backup with encrypted data and everything), then for our system, the "new" app is the same user/same device.

Is there any chance to prevent this behavior? we might have users paying just for one device when they could be using several ones.

Thanks in advance!

fabiocaccamo commented 2 years ago

@juangz the cloned device is supposed to replace the previous one, so technically this is the right behaviour. Unfortunately there is no way to prevent this scenario using only uuids, but if I understand well you can achieve what you need by using uuidForInstallation(which doesn't persist on system-reset / backup-restore in combination with a user account.

juangz commented 2 years ago

I thought about it replacing the existing one, so I could use the method to retrieve the UUID assigned to the user, but still not sure if that is the best way to go.

uuidForInstallation won't work, as users sometimes uninstall the app to start fresh again, and that shouldn't take an extra licence, and the only way to do that is if we always use the same UUID per device.

I'll try to think of another way to do this, but any help is appreciated! Thanks!

fabiocaccamo commented 2 years ago

I had a similar problem years ago, in the end the best solution is ask the user to login and store the auth token locally.

juangz commented 2 years ago

We are actually doing that.. we are not doing auto-login, but as the user might have several devices per account, then just login is not enough, as I need to have a different UUID per device.

When cloning the device, they are also cloning the DB and keychain, so they are already ready to use it without even doing a login as the device UUID is the same, and the user is already logged in into the app 😞

This is not an easy or clean task TBH

fabiocaccamo commented 2 years ago

@juangz this is the drawback, the alternative is do not sync the device uuid on iCloud.

I close this issue because it is not a problem that can be solved by changing the library.