javascript - 反应本机 PushNotification.cancelLocalNotifications 不起作用
问题描述
我正在尝试使用 RN 和 zo0r / react-native-push-notification 做简单的提醒应用程序,但我无法从其操作中取消通知。这是创建通知的方式:
PushNotification.localNotificationSchedule({
id: id.toString(),
number: 0,
userInfo: {
id: id.toString(),
},
channelId: 'channel-@' + id,
title: title,
message: text,
ongoing: ongoing,
date: new Date(dateFrom),
allowWhileIdle: true,
actions: ['Complete'],
playSound: true,
invokeApp: false,
autoCancel: false,
data: {
id: id.toString(),
},
});
id 根据之前的通知返回简单的整数 - 1 或 2 或 3 等。
我在 index.js 中使用此代码执行了一个“完成”操作
onAction: function (notification) {
finishNote(notification.data.id)
},
并按下“完成”按钮,我从外部文件调用此函数:
export default function finishNote(notificationId) {
PushNotification.cancelLocalNotifications({id: notificationId.toString()})
}
按下“完成”按钮后没有任何反应,我试过了
PushNotification.cancelAllLocalNotifications()
这有效,但是,我需要取消特定的。
请问有什么想法吗?
解决方案
推荐阅读
- ios - ARKit:如何仅检测不包括障碍物的水平地板
- spring-boot-admin - 防火墙后的 Spring Boot 管理员
- postgresql - 获取 PostgreSQL 中的每个用户角色
- java - 如何检查for循环内的if语句是否从未使用过?
- java - 如何在 TestNG 中实现方法的可重用性
- java - 在 Eclipse 中使用 Java 多线程不再终止 Java 主类线程
- angular - 如何在 Angular 中编写自定义的特殊属性绑定?
- label - AmCharts 将背景颜色添加到 valueAxes 指南标签
- python - 用户警告:布尔系列键将被重新索引以匹配 DataFrame 索引
- javascript - 背景图像 url 中的属性