Ionic-24小时后开始安排本地通知

时间:2020-01-05 00:46:43

标签: javascript angular typescript algorithm ionic-framework

我正在尝试实施本地通知,以通知应用程序用户其用药情况。我使用离子局部通知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,
}

请问我在哪里弄错了?

0 个答案:

没有答案