1

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?

kris
  • 11,868
  • 9
  • 88
  • 110
  • I m wondering why this info (UUID or IMEI no) cant be stored on server side on first access and then can be referred on any subsequent access? This way the implementation will be fool proof and we need not have to really worry about app uninstalls – Gandhi Jul 26 '17 at 08:11
  • @Gandhi - iOS does not give developer access to UUID (https://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now), nor to IMEI (https://stackoverflow.com/questions/19927160/finding-imei-number-using-objective-c) – kris Jul 26 '17 at 21:19
  • did you checked this link - https://stackoverflow.com/questions/21878560/how-to-preserve-identifierforvendor-in-ios-after-uninstalling-ios-app-on-device%3E there are ways to resolve this problem – Gandhi Jul 27 '17 at 06:57
  • You are correct - there are solutions for that - and the iOS link in answer provide below by @Merka uses that same technique. I am still hoping there might be a cross platform Cordova plugin solution - however it is a small hope at this stage. – kris Jul 28 '17 at 02:42

2 Answers2

1

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).

Akram
  • 2,158
  • 1
  • 17
  • 24
1

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

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • Thanks @Gandhi - I just tried this plugin on both an iOS and Android device - deleting then reinstalling the app - on the 2nd run it reported the same UUID as the first run, on each device. I realise it may not be 100% foolproof, and appreciate your link to the documented issue, but that it is going to work most of the time is a good enough solution for me. – kris Jul 31 '17 at 05:06
  • @kris Glad it helped. Cheers – Gandhi Jul 31 '17 at 06:05