Reputation: 12590
I am creating a Cordova mobile app that will have a local database that will store some user-chosen settings. I will also be sending the user preferences to a server.
I would like the user preferences to persist even if they delete the app and reinstall it.
It would also be desirable if the preferences persisted across multiple devices the user owns (via their Google Play account, or their Apple ID), but that is not critical.
I don't want the user to need to create an account for my app.
One option is to get the UDID of the device and use that to reconnect to the "same" account but I understand that is not actually reliably the same after multiple installs.
Ideal is probably like the Google Play account, and the iTunes Account. I've seen Android games and Apple apps that use that. Is there a Cordova plugin that gives access to both of those?
What is a good simple solution for a cross-platform app to know if it running on the same device as it was previously run on?
Upvotes: 1
Views: 697
Reputation: 2198
For iOS :
You can do this by using this library (or just implement it for your own use in your code). The uid
of this process is saved in device's keystore
and will be the same even when app is uninstalled and installed again several times. Also you can have the same uid
for this user using iCloud synchronization.
For Android:
This SO answer is a good solution. Although it may change if user flash its phone. If it is very critical for you to have a unique id for every device, imei
will be a good choice for you in android phones but it needs READ_PHONE_STATE
permission. To synch this id
over devices you need to map it to something like login information or so. To my knowledge, you can't do it without such mapping.
To use these solution in Cordova
you need to put this code in a library (i.e. .jar
or .framework
file) and create a plugin for your Cordova
app to call getUid()
method of these libraries (assuming that you named the method that returns the unique identifier, getUid
).
Upvotes: 1
Reputation: 11935
After digging deep into this issue, I could get one ready-made plugin which should possible resolve this issue - UniqueDeviceID plugin
The plugin claims that the ID remains the same after app uninstalls. But I could see somebody facing issue after app updates as it returns different IDs. Some solutions have also been posted on the same issue comments.
Nevertheless, this is the only plugin I could find matching the OP's requirement to the closest. Even if some tweaks needs to be done to address some issues, I feel this plugin should be the starting point. Hope it helps. Cheers
Upvotes: 1