无法使用React Native Firebase在真实设备上显示通知

时间:2018-07-18 15:01:15

标签: react-native push-notification firebase-cloud-messaging react-native-firebase

我有一个应用程序,该应用程序使用react native和firebase进行推送通知。 这是我发送给客户的通知:

   'data' : {
        'title' : ' ' + this.currentUser.email + ' send you a message !',
        'text' : text,
        'senderName' : this.currentUser.email,
        'senderUid': this.currentUser.uid   
    }

我使用仅数据消息,并且在我的代码中实现了一个接收通知的侦听器:

this.onMessageListener = firebase.messaging().onMessage((message) => {
                senName = message.data.senderName;
                senUid = message.data.senderUid;

                const showNotif = new firebase.notifications.Notification()
                    .setNotificationId('notificationId')
                    .setTitle(message.data.title)
                    .setBody(message.data.text)
                    .android.setChannelId('channel_id_foreground')
                    .android.setSmallIcon('ic_launcher');
                firebase.notifications().displayNotification(showNotif)
            })

我已经在模拟器中测试过,一切正常。当我在真实设备上运行它时,它可以调用onMessage,但是firebase.notifications().displayNotification(showNotif)无法正常工作。它无法在屏幕上显示通知。 有人知道这个问题吗?

1 个答案:

答案 0 :(得分:0)

我认为您的问题对设备具有相对权限,您是否要求对设备授予授予权限?如果用户已授予权限,则应检查android和ios设备上的应用程序,因为有时ios 9不支持在前台运行该应用程序时显示通知。