【发布时间】:2017-10-25 11:30:49
【问题描述】:
我在这方面发现了很多旧的线索,但我没有找到明确的答案来让本地通知点击事件在应用程序被终止后工作。如果应用程序处于活动状态或在后台,通知将起作用。为了测试,我编写了以下代码。
app.initEvents = function() {
"use strict" ;
var fName = "app.initEvents():" ;
app.consoleLog(fName, "entry") ;
cordova.plugins.notification.local.isPresent(1, function (present)
{
if (! present) {
var d = new Date();
d.setMinutes(d.getMinutes() + 2);
cordova.plugins.notification.local.schedule({
id: 1,
title: "Test message",
message: "Message body",
date: d
});
}
});
cordova.plugins.notification.local.on("click", function (notification, state) {
alert(notification.id + " was clicked -> app.Ready");
}, this);
var el, evt ;
if( navigator.msPointerEnabled || !('ontouchend' in window))
evt = "click" ;
else
evt = "touchend" ;
app.hideSplashScreen() ;
app.consoleLog(fName, "exit") ;
} ;
document.addEventListener("app.Ready", app.initEvents, false) ;
发生的情况是通知已安排并在 2 分钟后显示。如果应用程序同时被杀死,通知仍然被触发,但点击事件没有被处理并且通知被重新安排。所以我假设通知在被点击后被清除,并且因为 app.ready 事件稍后被处理它无法处理点击事件?
有没有办法让它工作?我正在使用插件的 CLI 6.5 和 0.8.4 版本。我只在 Android 7.1.1 上测试过。
【问题讨论】:
-
以上案例你找到解决办法了吗?
标签: android cordova notifications