Cordova Katzer本地通知在0.8之后破裂。无法在循环中安排多个通知

时间:2015-04-11 09:13:22

标签: ios cordova notifications ionic

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

我将插件从0.7.8更新为0.8.1

之前我能够在循环之后安排一个接一个的通知。现在我不能。

// 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)

})

以下代码在控制台中给了我这个。所以只安排了最后一个通知。

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

如何安装插件版本0.7.8。当我尝试时,我收到错误,说插件的I​​D不匹配?

1 个答案:

答案 0 :(得分:0)

您的问题是您编写数据的方式是错误的。 你应该使用:

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

别忘了把最后一个逗号。我犯了同样的错误,这对我有用。