0

This is my code on the app on phonegap to obtain the registration ID. The registration ID is always obtained successfully.

const push = PushNotification.init({

    android: {
    },
    browser: {
        pushServiceURL: 'http://push.api.phonegap.com/v1/push'
    },
    ios: {
        alert: "true",
        badge: "true",
        sound: "true"
    },
    windows: {}

});

push.on('registration', function ( data ) {

    recordRegistrationID( data.registrationId ); //Pseudo

});

push.on('notification', function ( data ) {

    // data.message,
    // data.title,
    // data.count,
    // data.sound,
    // data.image,
    // data.additionalData

});

push.on('error', (e) => {

    // e.message

});

Then I try to send a push notification to that device with the stored registration ID from my PHP server (example.com) by cURLing it to Firebase Cloud Messaging API, it always returns MismatchSenderId.

{"multicast_id":6660509895358893455,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

I already tried to compile the .APK and run it on my mobile device. I always successfully get the token, but the message can never be sent to that registration ID retrieved by the PhoneGap app.

Doing more research, it seems like that because PhoneGap actually retrieves the registration ID but it ties to PhoneGap itself as a sender, so other senders won't work.

Am I correct to assume this? If this is the case, how can I obtain the registration ID using PHP instead of PhoneGap, for Firebase Cloud Messaging?

Thank you.

cuzmAZN
  • 377
  • 1
  • 7
  • 25

1 Answers1

0

Doing more research, it seems like that because PhoneGap actually retrieves the registration ID but it ties to PhoneGap itself as a sender, so other senders won't work.

This seems like an odd behavior. The token generated is tied to an app instance and the Firebase project. Can you provide the link where this is mentioned? It doesn't make sense for the token associated to change to a different sender at all.

With that said, there is currently no way to get the registration token from your backend. As I mentioned above, the token is tied to the app instance, so it can only be generated on the client app side.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • That was actually my assumption after reading a lot of comments off Stackoverflow, for example, this: https://stackoverflow.com/questions/36534597/mismatchsenderid-error-from-gcm-using-gcm-push-notification?rq=1 Or from the documentation itself: "A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work." – cuzmAZN Oct 11 '18 at 16:10
  • Because my token was generated from Phonegap, I assume that only Phonegap has the authorization to receive the push? I have checked and am sure that all the server ID and other keys are correct. manifest.json also has the correct sender ID. – cuzmAZN Oct 11 '18 at 16:13
  • I haven't used PhoneGap before, but it would seem that you are hitting an error with it directly. Similar to [this issue](https://github.com/phonegap/phonegap-plugin-push/issues/1707) – AL. Oct 11 '18 at 16:33
  • Also, the token can no longer be tied to a *group of senders*. There was a feature before that made that happen during GCM, but in FCM, each token should only be tied to a single sender. See my [answer here](https://stackoverflow.com/q/50001001/4625829) for more details. – AL. Oct 11 '18 at 16:36