ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

Many NotRegistered error status #176

Closed alexislg2 closed 8 years ago

alexislg2 commented 8 years ago

Hey, I'm using your package with the Cordova Push plugin https://github.com/phonegap/phonegap-plugin-push

It works great. But after few days/weeks, my users start not receiving notifications. And when I look at the logs I receive NotRegistered errors with theses users.

When app sends a new regId I save it in my database (overwriting the previous one) and do the same when I receive a canonical_id. What am I doing wrong?

eladnava commented 8 years ago

@alexislg2 you are receiving NotRegistered because:

Is it possible that you released updates to your app recently and that your app doesn't re-register after updating?

alexislg2 commented 8 years ago

Hey thanks for your quick answer.

Thanks

eladnava commented 8 years ago

@alexislg2 are you registering every time the app is opened? That's very bad and could be the reason you are getting this error. You should not be registering unless the app is fresh-installed or updated, or the IDListenerService invokes the registration service for some other reason.

alexislg2 commented 8 years ago

Oh oh that's interesting. Actually this is the way the Phonegap/cordova Pushplugin is coded. I will tell the developers about that. Do you have a link to the documentation that says we should register only after APK updates?

Thanks

eladnava commented 8 years ago

In Google's official GCM Client Demo App they register to GCM only when a new version of the application is installed on the device. Therefore I assume that's the best practice.

Check out this StackOverflow question which addresses this issue in regards to Cordova/PhoneGap.

I remember having similar problems with my app when I also re-registered devices every time the app was opened.

alexislg2 commented 8 years ago

OK according to the SO post, it does not seem to be so bad to register at every start, just a waste of time and data I think.

eladnava commented 8 years ago

@alexislg2 I recall having a similar issue where devices would not receive push notifications and I was able to solve it by not re-registering every time the app is restarted. I'd recommend avoiding it if you can, as it doesn't follow the GCM registration workflow:

  1. The client app obtains a registration token using the Instance ID API. The call to this API must have the authorized entity set to your app server's sender ID, and the scope set to the appropriate value for GCM (depending on your platform).
  2. The client app passes the registration token to the app server.
  3. The app server saves the registration token and acknowledges to the client app that the process completed successfully.

If the app server fails to complete its part of the registration handshake, the client app should retry sending registration token to the server or delete the registration token.

https://developers.google.com/cloud-messaging/registration

hypesystem commented 8 years ago

@alexislg2 what is the status on this? Have you resolved your issue?

Either way, it seems it is not a node-gcm issue so I am going to close the issue on here :smile: let me know if this assumption is wrong