在React Native Firebase中处理组通知

时间:2019-06-30 12:30:42

标签: firebase react-native notifications firebase-cloud-messaging

我正在尝试使用Firebase云消息传递处理我的React本机项目中的组通知。通知在前台/背景中正确发送,当应用程序被杀死时,但我在分组通知时遇到问题。正如文档所说,我使用了groupChannel,但是当通知已发送到设备时,新的将替换旧的。 这是我通过邮递员发送的邮件: {     “至”:“我的令牌”,     “ priority”:“ high”,     “数据”:{         “ title”:“我的标题”,         “ body”:“ Lorem”,         “远程”:是的,         “ sound”:“默认”,         “ priority”:“ high”,         “ groupId”:“ Group2”,         “ tag”:“ GroupTag”     }

}

这是我的代码:

   this.notificationListener =  firebase.messaging().onMessage(async message=>{
  console.log(message,'foreground')

    const {body,title,sound,groupId,tag} = message.data;
    const GroupChannelId = new firebase.notifications.Android.ChannelGroup(
      groupId,
      'Group')
      firebase.notifications().android.createChannelGroup(GroupChannelId);
      const localNotification = new firebase.notifications.Notification()
      .setTitle(title)
      .setBody(body)
      .setData(message.data)
      .setNotificationId(groupId)
      .android.setGroup(groupId)
      .android.setBigText(body)
      .android.setVibrate([600,300,200,300,500])
      .android.setAutoCancel(true)
      .android.setChannelId(groupId)
      .android.setGroupAlertBehaviour(firebase.notifications.Android.GroupAlert.Children)
      .android.setPriority(firebase.notifications.Android.Priority.High);

const date = new Date();
date.setMinutes(date.getMinutes() + 1);
firebase.notifications().scheduleNotification(localNotification,{
  fireDate:date.getTime()
})

  firebase.notifications().displayNotification(localNotification);

})

0 个答案:

没有答案