Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule a local notification every day with phonegap cordova

I'm developing an app with cordova and i'm using this plugin to schedule a local notification every day to 6 o'clock https://github.com/katzer/cordova-plugin-local-notifications

Everything works fine, this is the code that i'm using to set 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, 
    });

I was doing testing , and notification appears every day at 6 pm but only for 9 consecutive days and then stops appearing . What am I doing wrong?

Thanks

like image 875
josmarycarrero Avatar asked Feb 11 '15 21:02

josmarycarrero


1 Answers

Although its late, try the following at: https://github.com/katzer/cordova-plugin-local-notifications/wiki/11.-Samples

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

For tomorrow_at_6_am you can try the following:

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);
like image 154
nthapa Avatar answered Oct 06 '22 08:10

nthapa