【发布时间】:2018-12-23 14:57:35
【问题描述】:
我有一个使用 Firebase 推送远程通知的应用,一个客户端发送如下通知消息:
body: JSON.stringify({
'to' : 'token',
'notification' : {
'title' : ' ' + this.currentUser.email + ' send you a message !',
'body' : text
},
'data': {
'senderName' : this.currentUser.email,
'senderUid': this.currentUser.uid
}
})
和一个客户端实现接收通知的方法:
firebase.notifications().onNotification((notification) => {
const showNotification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(notification.title)
.setBody(notification.data.text)
.android.setChannelId('channel_id_foreground')
.android.setSmallIcon('ic_launcher');
firebase.notifications().displayNotification(showNotification)
});
当我的应用程序在前台运行时,通知正常显示,但在后台时,它可以在通知托盘中接收,但不会将该通知显示到设备屏幕上。
通知显示如下:
我希望通知可以显示如下:
补充:如果我通过滑动关闭应用并发送通知,我的应用将崩溃。
谁能帮帮我?
【问题讨论】:
-
问题很明显。如果使用通知消息并且应用程序在后台,则无法触发侦听器 onNotification。通知只显示在通知托盘中。
-
附加:这一行 classpath 'com.google.gms:google-services:4.0.1' 如果在应用关闭时收到通知,可能会使应用崩溃/刷卡。解决这一变化:classpath 'com.google.gms:google-services:3.2.1' 或更低
-
你找到解决办法了吗?
-
我也遇到了同样的问题,你们找到解决办法了吗?
标签: firebase react-native push-notification firebase-cloud-messaging