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 208 forks source link

GCM topic messaging not arriving on iOS device #257

Closed joaoBeno closed 8 years ago

joaoBeno commented 8 years ago

Hello there, sorry if my question should be elsewhere... I'm finishing an simple iOS app I did to learn Swift, and I can't get my server to send a topic message to my device, but the message arrive if I send it trough the Firebase Panel... My code:

function enviarNotificacao(Chave) {
    var message = new gcm.Message({
        delayWhileIdle: false
    });
// Set up the sender with you API key
    var sender = new gcm.Sender('**Api Key shown on FCM panel...');

// Send to a topic, with no retry this time
   sender.sendNoRetry(message, {topic: '/topics/editorial-politico-' + Chave}, function (err, response) {
       if (err) console.error(err);
       else    console.log(response);
   });
}

What I'm missing? this code works on (Some) Android...

hypesystem commented 8 years ago

Hey @joaoBeno ! You are asking the question the right place :smile:

It doesn't look like you are passing your message any content to show on the recipient device. If you want to directly trigger a notification, look into the notification field.

For iOS devices, additionally, you need to set priority: "high".

I would recommend you read through this project's README to get an understanding of how to use it.

To understand FCM you could also check out the documentation: https://firebase.google.com/docs/cloud-messaging/http-server-ref

joaoBeno commented 8 years ago

Hey, thanks, I will try it now! Another quick question: so I will need separate channels for iOS and Android, since in Android I should not be sending priority: "high" to save some battery, is that right?

Ps.: It worked! 👍

hypesystem commented 8 years ago

Oh. yeah, I see that I left that sentence hanging a bit. You need to set priority: "high" if you want the device to receive you notifications even if it isn't in the foreground. So in that case, yes, you would need separate channels for Android and iOS (unfortunately!).

This, at least, was the case last time I implemented notification support for both device types in a system, and I don't think it has changed. You can test and see if it works otherwise :smile: