如何动态地在“$ cordovaLocalNotification.schedule”中为多个ngCordova本地通知添加文本?

时间:2015-06-30 19:54:58

标签: javascript android angularjs ionic ngcordova

以下是ngCordova文档显示如何添加多个本地通知的方式

cordova.plugins.notification.local.schedule([{
    id: 1,
    text: "Multi Notification 1",
    sound: isAndroid ? 'file://sound.mp3' : 'file://beep.caf',
    at: dateObject,
    autoCancel: true
},{
    id: 2,
    title: "Local Notification Example",
    text: "Multi Notification 2",
    at: dateObject,
    autoCancel: true
}]);

我正在迭代来自数据库的数据,所以我有动态“id”和“日期对象”。我在一个循环中运行它,但只有最后一个通知被安排,即使当id不同,所以我发现我需要传递如上所示的“cordova.plugins.notification.local.schedule”中的对象数组来完成它但我不知道我不知道如何动态地做到这一点。 请帮助我提交我的项目,这是困难的。

services.js

        for(var i in TestTimeTable)
        {
            var notificationDate = new Date(TestTimeTable[i].year, TestTimeTable[i].month, TestTimeTable[i].day, TestTimeTable[i].hour, TestTimeTable[i].minute, 0, 0);
            var notificationID = i + ref.getAuth().uid;


              $cordovaLocalNotification.schedule({
                id: notificationID,
                title: 'Feedback Reminder',
                text: 'Please Provide Lecture Feedback',
                at: notificationDate,
                autoCancel: true
              }).then(function (result) {
              });

        }

        cordova.plugins.notification.local.on("click", function (notification, state) {
            $state.go('courses');
        }, this)

    });

1 个答案:

答案 0 :(得分:0)

现在有效,问题是通知ID(var notificationID = i + ref.getAuth()。uid;)不是数字。感谢