11

I need to get any number, serial, key or whatever to identify every device where my phonegap app is running, I think uuid also changes when the app updates so it wouldn't work for me.

The scenario here is that the user can synchronize data from the app, so I need to know which device has synchronized and which has not, or if it needs to update new data that maybe others devices have already done, etc

any ideas?

beaver
  • 17,333
  • 2
  • 40
  • 66
Agustín
  • 1,546
  • 7
  • 22
  • 41
  • I think I have figured out a way to make this do what you want with a couple caveats, but it will survive multiple app installations at least on iOS. What platforms are the most important for the purposes of this discussion? – Dustin Simpson Feb 15 '16 at 21:56
  • 2
    @r3wt Have you already checked this cordova plugin? https://github.com/Paldom/UniqueDeviceID – beaver Feb 16 '16 at 12:24
  • 1
    @r3wt Do you need a solution for which kind of platforms (Android, iOS, ...)? – beaver Feb 17 '16 at 12:35
  • @beaver your answer does the trick i think. thanks man. – r3wt Feb 17 '16 at 23:02
  • 1
    @r3wt I added the answer, please vote it if you believe and it satisfies your requirements – beaver Feb 18 '16 at 06:56

3 Answers3

10
<script type="text/javascript" charset="utf-8">

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    var element = document.getElementById('deviceProperties');
    element.innerHTML = 'Device Model: '    + device.model    + '<br />' +
                        'Device Cordova: '  + device.cordova  + '<br />' +
                        'Device Platform: ' + device.platform + '<br />' +
                        'Device UUID: '     + device.uuid     + '<br />' +
                        'Device Version: '  + device.version  + '<br />';
}

</script>

After getting the device info you can apply your logic to validation.

Refer: http://docs.phonegap.com/en/3.2.0/cordova_device_device.md.html#Device

Purus
  • 5,701
  • 9
  • 50
  • 89
9

I suggest to use this PhoneGap/Cordova plugin:

https://github.com/Paldom/UniqueDeviceID

As declared in the documentation

it remains the same after app uninstall.

beaver
  • 17,333
  • 2
  • 40
  • 66
  • 1
    On iOS, the plugin merely generates a unique UUID and stores it in the keychain for the user. If that entry gets deleted, the next one will be different. – rob3c Dec 07 '17 at 21:32
3

When a user first installs the app you could make an API call to get a unique ID from the system you are using to sync data and then you could store that ID in a localStorage variable, or to a database table. Then you refer to that ID stored on the device when making calls.

Dawson Loudon
  • 6,029
  • 2
  • 27
  • 31
  • 3
    yea I thought of that, but what if the users uninstall the app? that is a pain in the ass, I first thought about using the imei number but wouldn't work on tablets – Agustín Dec 03 '13 at 19:54
  • 1
    Yeah, may need to consider a signup in that case. Then you can also cover the instance of a user getting a new device, or if they need to RMA their device for the same device. – Dawson Loudon Dec 03 '13 at 20:33