首页 > 解决方案 > 无法使用反应原生 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)
            })

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

标签: react-nativepush-notificationfirebase-cloud-messagingreact-native-firebase

解决方案


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


推荐阅读