Getting device id

Hello, is there a way to get the device id other than on device ready?
I am writing a server script that would get your device id when you login and save it in a collection with the user id and device id for push notifications to that device only.

But I can't seem to be able to get the device id from my sign in screen to pass it to the rest api.

Please advise if there is a work around as the devices collection is not associated with the users collation.

Thank you
1 person has
this question
+1
Reply
  • Hello,

    Do you use Push notifications here?
    What is the type of your project JQM or Ionic?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Hi Serhii, push notification is working. I am just trying to save the device id and the user id in a collection together for later use to send a push to that user id only.

    Right now on device ready, it shows null when I alert push notification id after 1 second. I even tried saving it on to another storage variable so I can access it later. But when I invoke the service to save the user id and device id to a collection on sign in, the user id is saved but not the device id.

    Please let me know how I can get this to happen. Thank you
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Please check the variable from the localStorage:
    localStorage.getItem('pushNotificationDeviceID');
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • Michael, Are you trying to ave the device id to the Users table?
    If so I think despite the fact you can add additional columns to the Users table you can't work with them. This would explain the null return.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated indifferent, undecided, unconcerned

  • I tried what was suggested and it still reports null. I saved the pushNotificationDeviceID to another storage variable called this_device_id on device ready. Then I tried to display the this_device_id variable on page show and it returns null the first time the app is launched. Seems to work the second time and after.

    Is there a time frame before the id is stored in the storage variable?
    the examples show 1ms but 1.5 seconds does not appear to be enough ether. Since I would not be able to tell the user to relaunch the app after install It would be helpful to find a way to get the device id the first time user launch the app on the device. I have attached screenshots of my code and of the phone.

    First one is when app is launched the first time and the second one is when I close and reopen the app
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated indifferent, undecided, unconcerned