不显示应用程序的通知操作按钮操作

Notification action buttons action without showing the app

我有一个带有操作按钮 'Start' 和 'Remind later' 的本地通知。当我点击两者中的任何一个时,应用程序打开。我想为“开始”按钮保留它,但对于“稍后提醒”按钮,我想在不打开应用程序的情况下静默 运行 一些代码(稍后重新安排通知)。

这可以吗?

    function onOpened(notification) {
        if (notification.action == 'Start') {
            cancelNotification(notification.id)
            NavigationService.navigate(notification.title)
        } else {
            cancelNotification(notification.id)
            // reschedule
            let dateTime = new Date(notification.fireDate)
            dateTime.setMinutes(dateTime.getMinutes() + 30)
            scheduleNotification(notification.id, notification.title, notification.message, dateTime)
    }
}

此代码有效,但正如我所说,它将应用程序带到前台,我想避免它。

如果您寻求帮助,您需要包含完整代码,但从您的标签来看,我假设您使用的是 React Native Push Notifications. If that's the case you might want to look at this Action click brings the app from background to foreground 问题。基本上,您需要通过一些本机代码并更改几行。