首页 > 解决方案 > 反应本机 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()

这有效,但是,我需要取消特定的。

请问有什么想法吗?

标签: javascriptreactjsreact-nativepush-notificationnotifications

解决方案


推荐阅读