我正在尝试实施本地通知,以通知应用程序用户其用药情况。我使用离子局部通知plugin。
但是我有一个问题,通知是在24小时之后开始工作,而不是从我坐在firstAt
起的时间
代码:
scheduleNotification(med: Med) {
let everyXHours = Math.floor(24 / med.frequency);
let timesPerDay: moment.Moment[] = []
for (let i = 0; i < med.frequency; i++) {
const time = moment(med.firstAt).add(everyXHours * i, "hour");
timesPerDay.push(time);
}
for (let i = 0; i < timesPerDay.length; i++) {
let randomID = Math.floor(Math.random() * 10000);
//TODO: fix the bug that notifications start to appear in the next day;
this.localNotifications.schedule({
id: randomID,
title: 'Medication Reminder',
text: `You should take ${med.name} now`,
trigger: {
firstAt: timesPerDay[i].toDate(),
every: ELocalNotificationTriggerUnit.DAY
},
foreground: true
});
}
}
医生:
export interface Med {
name: string,
firstAt: moment.Moment,
frequency: number,
}
请问我在哪里弄错了?