Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
515 stars 197 forks source link

GCM token field lost randomly. #309

Open pptoan23 opened 7 years ago

pptoan23 commented 7 years ago

Hi, I use Meteor 1.2.1. And I have problem with GCM token field of _raix_push_app_tokens, they lost randomly although user still logged in. I suspect the below code from "push/lib/server/server.js":

Push.appCollection = new Mongo.Collection('_raix_push_app_tokens');
Push.addListener('token', function(currentToken, value) {
  if (value) {
    // Update the token for app
    Push.appCollection.update({ token: currentToken }, { $set: { token: value } }, { multi: true });
  } else if (value === null) {
    // Remove the token for app
    Push.appCollection.update({ token: currentToken }, { $unset: { token: true } }, { multi: true });
  }
});

When does this listener is called with "null" value? Note: I use micro services and they are working with the same DB. Thank you!

pptoan23 commented 7 years ago

The problem with me is "NotRegistered" error response from GCM. The token was registered before and worked well untill "NotRegistered" appear. I changed to FCM service and got the same issue. What should i do with it?

da314pc commented 7 years ago

I am experiencing the same issue

If the client app unregisters with GCM. If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNS Feedback Service reported the APNS token as invalid. If the registration token expires (for example, Google might decide to refresh registration tokens, or the APNS token has expired for iOS devices). If the client app is updated but the new version is not configured to receive messages.


Maybe try to upgrade the package on all your clients. Some of the old packages using GCM, while the server uses FCM

da314pc commented 7 years ago

@pptoan23 Yea I was having the same issue. You are experiencing invalid tokens.

This code: "Push.appCollection.update({ token: currentToken }, { $unset: { token: true } }, { multi: true });" is correct.

To fix your issue you have to keep track of invalid tokens, and force the onTokenRefresh handler, which you can call by using push.unregister(successCallback, errorCallback).

So when the users opens the app again they will have a correct token.

raix commented 6 years ago

Tracking this...

bdevalia commented 6 years ago

@raix Was this issue fixed ? I am getting same error. Shall i assume that below should be done in client and not server ? Also what action should be taken on successCallback "To fix your issue you have to keep track of invalid tokens, and force the onTokenRefresh handler, which you can call by using push.unregister(successCallback, errorCallback)."