以下是 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”中所示的对象数组才能完成,但我没有不知道如何动态地做到这一点。请帮助我需要提交我的项目,这被卡住了。
服务.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)
});