使用phonegap cordova每天安排本地通知

时间:2015-02-11 21:44:25

标签: cordova notifications phonegap-plugins localnotification

我正在使用cordova开发应用程序,并且我使用此插件每天安排本地通知到6点钟 https://github.com/katzer/cordova-plugin-local-notifications

一切正常,这是我用来设置de Notification

的代码
/*Set 6 o'clock*/
function setTestAlarm() {
    var notify = new Date();
    notify.setHours(18,00,00,00);

  localNotification.add({
        id:      1,
        title:   'My app',
        message: 'Hi this is a notification',
        repeat:  'daily',
        date:    notify,
        autoCancel: true, 
        ongoing: true, 
    });

我正在进行测试,并且通知每天下午6点出现,但仅连续9天,然后停止出现。我做错了什么?

由于

1 个答案:

答案 0 :(得分:8)

虽然已经很晚了,但请尝试以下方式:here

cordova.plugins.notification.local.schedule({
    id: 1,
    text: "Good morning!",
    firstAt: tomorrow_at_6_am,
    every: "day" // "minute", "hour", "week", "month", "year"
});

对于tomorrow_at_6_am,您可以尝试以下操作:

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate()+1);
tomorrow.setHours(6);
tomorrow.setMinutes(0);
tomorrow.setSeconds(0);
var tomorrow_at_6_am = new Date(tomorrow);