I am using 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. However, the function don't seems to work. I'm not quite sure where is the problem over here.
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
});
};
After some trial and errors, here's my findings. This solution defines certain attributes differently from katzer's scheduling. In this case, the 'at' attribute is defined as 'date' and 'text' is defined as 'message' in local-notification.js. Besides, the plugin is defined as 'add' instead of 'schedule', while the plugin is called by 'window.plugin.notification......' instead of 'cordova.plugins.notification......'.
This is the working code.
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>