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)
不能按预期工作。它无法在屏幕上显示通知。有人知道这个问题吗??
解决方案
我认为您在设备上发布了相关权限,您是否请求在设备上授予权限?如果用户已授予权限,您应该检查 android 和 ios 设备上的应用程序,因为有时 ios 9 不支持在应用程序在前台运行时显示通知。
推荐阅读
- python - 查找和使用形状位置 Python pptx
- python - 如何将数据框除以同一数据框的另一列
- javascript - 替换对象数组中的字符
- github-api - 特定回购的 Stargazer 计数
- php - 弹出在 php 退出意图中发布的电子邮件表单
- javascript - React Hooks - 本地天气 API
- javascript - Javascript Html 树
- ruby-on-rails - Rails 测试跳过自定义验证或自定义验证不起作用?
- java - 来自 URL 的 Java JFrame setImageIcon 图像不起作用
- amazon-s3 - AWS S3 lambda 上传返回 413 请求太长