react-native - 当应用程序关闭时,我可以使用 React Native 获得推送通知吗?
问题描述
当应用程序关闭时,我正在尝试使用 React-Native/RNFirebase 在 IOS 上获取通知并更新启动器图标徽章。但不幸的是,RNFirebase 似乎没有任何支持。关闭应用程序时,onNotification() 侦听器似乎不起作用。(在 XCode 上启用了后台模式/推送通知)
收到通知并关闭应用程序时,是否有任何解决方法可以更新启动器图标徽章?
解决方案
如果您的应用已关闭,您可以使用以下命令检查它是否被通知打开:
firebase.notifications().getInitialNotification()
这是一个使用它的示例:
const notificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen && notificationOpen.notification) {
let { title, body, data } = notificationOpen.notification;
if (!title && !body) {
title = data.title;
body = data.body;
}
const notification: Notification = notificationOpen.notification;
//firebase.notifications().removeDeliveredNotification(notification.notificationId);
this.handleNotificationActions(
title,
body,
data,
navigator,
t,
"background"
);
}
推荐阅读
- cypress - 在 cypress CI E2E 的浏览器中使用特定的 flash 播放器版本
- android - Flutter Android InAppWebView 摄像头和麦克风被阻止
- pandas - 生成具有从今天开始的时间序列索引和固定间隔的数据帧
- java - jdbcTemplate.queryForList(query) 的 SONAR“SQL 注入”气味
- javascript - JavaScript:箭头函数中的 this 关键字访问问题
- javascript - 非角度类如何使用角度服务及其部门
- java - 在 JavaParser 中创建无效的 AST
- linux - linux shell 错误:noclobber 选项
- c# - 如何在没有循环的情况下从 list2 更新静态 list1 如何以 LINQ lambda 表达式的方式实现这一点
- mysql - mysql选择当前位置的计数器