【问题标题】:Can not show notification on real device using react native firebase无法使用反应原生 Firebase 在真实设备上显示通知
【发布时间】:2018-07-18 15:01:15
【问题描述】:

我有一个使用 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-native push-notification firebase-cloud-messaging react-native-firebase


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      相关资源
      最近更新 更多