Firebase 应用程序处于后台时通知无法正确显示(React Native)

Firebase 应用程序处于后台时通知无法正确显示(React Native),firebase,react-native,push-notification,firebase-cloud-messaging,Firebase,React Native,Push Notification,Firebase Cloud Messaging,我有一个应用程序,使用Firebase推送远程通知,一个客户端发送通知消息,如下所示: body: JSON.stringify({ 'to' : 'token', 'notification' : { 'title' : ' ' + this.currentUser.email + ' send you a message !',

我有一个应用程序,使用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()方法永远不会被调用,因此通知通道永远不会设置。根据通知,没有频道将不会出现

以下是对我有效的方法:如果您希望通知在android中显示为提示通知,请修改您的消息正文以包含您的频道ID,如下所示:

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 
        },
        'android': {
            'priority': 'high',
            'notification': {
                'channel_id': 'channel_id_foreground',
            },
        }
    })

问题很明显。如果使用通知消息且应用程序处于后台,则无法触发侦听器onNotification。通知仅显示在通知栏中。附加:此行classpath'com.google.gms:google services:4.0.1'如果在应用程序关闭/刷卡时收到通知,可能会使应用程序崩溃。要解决更改为:classpath'com.google.gms:google services:3.2.1'或更低版本的问题,您是否找到了解决方案?我面临着同样的问题,你们找到了解决方案吗?