Tariq
Tariq

Reputation: 1

Cordova Katzer Local Notifications broken after 0.8. Not able to schedule multiple notifications in a loop

https://github.com/katzer/cordova-plugin-local-notifications/

I updated the plugin from 0.7.8 to 0.8.1

Before I was able to schedule notifications one after each after in a loop. Now I cannot.

// Next 4 days
var today0 = new Date().setDate(new Date().getDate());
var today1 = new Date().setDate(new Date().getDate() + 1);
var today2 = new Date().setDate(new Date().getDate() + 2);
var today3 = new Date().setDate(new Date().getDate() + 3);
var today4 = new Date().setDate(new Date().getDate() + 4);



$ionicPlatform.ready(function() {

    cordova.plugins.notification.local.cancelAll(function() {

        cordova.plugins.notification.local.schedule({
            id: 0,
            at: new Date(today0),
            title: "Today 0"
        });
        cordova.plugins.notification.local.schedule({
            id: 1,
            at: new Date(today1),
            title: "Today 1"
        });
        cordova.plugins.notification.local.schedule({
            id: 2,
            at: new Date(today2),
            title: "Today 2"
        });
        cordova.plugins.notification.local.schedule({
            id: 3,
            at: new Date(today3),
            title: "Today 3"
        });
        cordova.plugins.notification.local.schedule({
            id: 4,
            at: new Date(today4),
            title: "Today 4"
        }); 

    });

    $timeout(function(){
        cordova.plugins.notification.local.getAll(function (notifications) {
            console.log(notifications)
        });
    },5000)

})

The following code gave me this in the console. So only the last notification is being scheduled.

[{"at":1429088652,"id":"4","title":"Today 4","text":"","badge":0,"sound":"res://platform_default"}]

How can I install plugin version 0.7.8. When I try, I get an error saying the id of the plugin doesn't match?

Upvotes: 0

Views: 598

Answers (1)

Pompetteuh
Pompetteuh

Reputation: 26

Your problem is that the way you write your data is wrong. You should use :

    cordova.plugins.notification.local.schedule(
    {
        id: 0,
        at: new Date(today0),
        title: "Today 0",
    },
    {
        id: 1,
        at: new Date(today1),
        title: "Today 1",
    });

Don't forget to put the last comma. I got the same mistake and this works for me.

Upvotes: 0

Related Questions