我正在使用插件在ionic 2应用程序中处理本地通知-
ionic cordova plugin add cordova-plugin-local-notification
npm install @ionic-native/local-notifications
该通知在ios设备中运行得非常好,但是对于android来说却显示出意外的行为。
异常行为- 在设定的时间重复同一天的通知。
当前行为 -通知持续一分钟。
我的要求是在每周的特定日期重复由用户设置的本地通知,该通知也应在用户设置的同一天和同一时间重复。
这是我的代码段-
makeLocalNotificationOn(mainDayNotifyObj, index) {
let currentDate = new Date();
let currentDay = currentDate.getDay(); // Sunday = 0, Monday = 1, etc.
let indexOfDay;
for (let i = 0; i < this.remainderDaysArray.length; i++) {
if (mainDayNotifyObj.dayName == this.remainderDaysArray[i]) {
indexOfDay = i;
break;
}
}
let setTime = mainDayNotifyObj.time.split(":");
let hours = parseInt(setTime[0]);
let minutes = parseInt(setTime[1]);
let firstNotificationTime = new Date();
let dayDifference = indexOfDay - currentDay;
if (dayDifference < 0) {
dayDifference = dayDifference + 7; // for cases where the day is in the following week
}
firstNotificationTime.setHours(firstNotificationTime.getHours() + (24 * (dayDifference)));
firstNotificationTime.setHours(hours);
firstNotificationTime.setMinutes(minutes);
let weekDay = firstNotificationTime.getDay();
let remainderObj = {
id: index,
title: 'Hello',
text: 'Its time',
foreground: true,
trigger: {every: {weekday: weekDay, hour: hours, minute: minutes},firstAt: firstNotificationTime}
};
this.notificationArray.push(remainderObj);
this.platform.ready().then(() => {
this.localNotifications.schedule(this.notificationArray);
});
}
任何帮助将不胜感激。谢谢
qq_花开花谢_0
相关分类