jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 48 forks source link

Collapsing notifications in iOS #82

Closed renatomotorline closed 3 years ago

renatomotorline commented 3 years ago

Hi,

Is possible to use the "apns-collapse-id" to collapsing notifications in iOS. I use the "tag" for android and works but I'm trying to do the same for iOS but without success.

Code:

var message = {
  to: `/topics/${id}`,
  time_to_live: 0,

  notification: {
    tag: id, // WORKING FOR ANDROID
    title: headings[lang],
    body: contents[lang]
  },

  apns: { // NOT WORKING
    headers: {
      "apns-collapse-id": id
    }
  },
};

/// Send notification
this.fcm.send(message, function (error, response) {
jlcvp commented 3 years ago

Hi renato, thanks for using the lib. I strongly recommend you to migrate to firebase node SDK instead of this lib but answering your question: Taking a look at the official documentation for FCM message structure, you will see that to collapse a notification you'll need to set the collapse_key value with a string identifier. You can have only 3 distinct keys at any given time, so use it with this in mind.


Oi renato, obrigado por usar a lib. Eu recomendo fortemente que tu migre pra o sdk pra nodeJS do firebase ao invés de usar essa lib. De qualquer forma, pra responder a tua pergunta: Na documentação do FCM a estrutura de mensagem tem suporte à chave collapse_key, assim tu não precisa tratar separadamente com instruçòes pro APNS. Só fica atento que tu só pode ter 3 keys direfentes no projeto