0

Using cordova plugin ktekosi-phonegap-plugin-push, I get the registrationID

var push = PushNotification.init({ "android": {"senderID": "my sender ID"}});

push.on('registration', function(data) {
    console.log(data.registrationId);
    document.getElementById("fcm_id").innerHTML = data.registrationId;
});

So I can use it by the server to send notification through FCM.

How can I get this registrationID fixed for all time? Is this an app specific ID or a user specific ID?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Matoeil
  • 6,851
  • 11
  • 54
  • 77

2 Answers2

1

Push registration ID will be changed with time. This is an usual case. This is neither an instance of the installed application nor app-specific or user-specific id.

When an app comes online you need to fetch the push registration ID and then pass it to your backend server each time to keep your backend server updated with the push registration ID.

Your backend server will then generate a push notification and will send it to FCM with the specific push registration ID it has. FCM then manages receiving the push notification in your mobile application.

I've answered a question here telling how push notification system works. You might have a look.

Update

Looks like google has changed its new gcm library as the answer stated here - https://stackoverflow.com/a/16839326/3145960. You might take a look at here. So, as I've read, the push registration id is updated only when app receives an update or the android os gets updated. Its much simpler now.

Community
  • 1
  • 1
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • thanks reaz! can u precise what u mean by 'app comes online' and 'each time'. – Matoeil Dec 14 '16 at 10:22
  • 1
    Application comes online and each time means the same actually. When you launch your application each time, you need to get the push registration ID first and have to send it to the server to keep the server updated with the latest push registration ID as I have stated before. – Reaz Murshed Dec 14 '16 at 10:24
  • 1
    ok thanks . what i quite don't understand is when exactly the registrationID is updated but thanks to u i have understood u need to keep a bi-directional communication between the server and the app – Matoeil Dec 14 '16 at 10:38
  • 1
    Great to know that helped! We don't actually know when the registration ID is updated. We don't actually have to bother about it too. – Reaz Murshed Dec 14 '16 at 10:40
  • well if the user dont lauch application for a long time it might stop getting notifications then if its been updated in the meantime, no? – Matoeil Dec 14 '16 at 10:51
  • Looks like google has changed its new gcm library as the answer stated here - http://stackoverflow.com/a/16839326/3145960. You might take a look at here. So, as I've read, the push registration id is updated only when app receives an update or the android os gets updated. Its much simpler now. – Reaz Murshed Dec 14 '16 at 15:22
  • i actually use fcm – Matoeil Dec 15 '16 at 15:32
  • FCM's core is composed of GCM itself. – Reaz Murshed Dec 15 '16 at 17:29
0

Try to use this plugin "cordova plugin add cordova-plugin-fcm". You can find detail here

To get Registration ID Use it like this

<script type="text/javascript">
          function onLoad() {
          document.addEventListener("deviceready", Fire, false);
                               }

            function Fire() {

                FCMPlugin.getToken(
                  function (token) {

                       alert(token)
                  },
                  function (err) {
                           alert("Error: " + 'error retrieving token: ' + err);
                  }
                );

            };


        </script>
 <body onload="onLoad();">
Anshul Khare
  • 391
  • 1
  • 4
  • 13