如何设置特定时间的本地通知?
How do i set local notification for a particular time?
我正在使用 this solution in my app and managed to get the basic local notifications working on app start. Currently I'm trying to schedule a local notification after 5 seconds using this function from katzer scheduling。但是,该功能似乎不起作用。我不太确定这里的问题出在哪里。
scheduleDelayed = function () {
var now = new Date().getTime(),
_5_sec_from_now = new Date(now + 5 * 1000);
cordova.plugins.notification.local.schedule({
id: 1,
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
badge: 12
});
};
经过反复试验,这是我的发现。 This solution defines certain attributes differently from katzer's scheduling。在本例中,'at'属性定义为'date','text'在local-notification.js中定义为'message'。此外,插件被定义为'add'而不是'schedule',而插件被'window.plugin.notification......'而不是'cordova.plugins.notification......'调用。
这是工作代码。
scheduleDelayed = function () {
var now = new Date().getTime(),
_5_sec_from_now = new Date(now + 5 * 1000);
alert(_5_sec_from_now);
window.plugin.notification.local.add({
id: 1,
title: 'Scheduled with delay',
message: 'Test Message 1',
date: _5_sec_from_now
});
};
<div class="container">
<button onclick="scheduleDelayed()">In 5 sec</button>
</div>
我正在使用 this solution in my app and managed to get the basic local notifications working on app start. Currently I'm trying to schedule a local notification after 5 seconds using this function from katzer scheduling。但是,该功能似乎不起作用。我不太确定这里的问题出在哪里。
scheduleDelayed = function () {
var now = new Date().getTime(),
_5_sec_from_now = new Date(now + 5 * 1000);
cordova.plugins.notification.local.schedule({
id: 1,
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
badge: 12
});
};
经过反复试验,这是我的发现。 This solution defines certain attributes differently from katzer's scheduling。在本例中,'at'属性定义为'date','text'在local-notification.js中定义为'message'。此外,插件被定义为'add'而不是'schedule',而插件被'window.plugin.notification......'而不是'cordova.plugins.notification......'调用。
这是工作代码。
scheduleDelayed = function () {
var now = new Date().getTime(),
_5_sec_from_now = new Date(now + 5 * 1000);
alert(_5_sec_from_now);
window.plugin.notification.local.add({
id: 1,
title: 'Scheduled with delay',
message: 'Test Message 1',
date: _5_sec_from_now
});
};
<div class="container">
<button onclick="scheduleDelayed()">In 5 sec</button>
</div>