使用 Ionic 2 LocalNotifications

Using Ionic 2 LocalNotifications

我需要有关 Ionic 2 本地通知的帮助!

我想让用户从日期时间选择器中选择一个小时,然后保存一个提醒,该提醒将在用户指定的时间时触发。

我有这个让用户,挑一个小时<ion-datetime pickerFormat="HH:mm" [(ngModel)]="time" cancelText="Cancelar" doneText="Aceptar"></ion-datetime>

<button ion-button block round (click)="saveReminder()">Guardar</button>

实际上,在 saveReminder() 中我有:

public saveReminder(): void {

        if (this.timePicked()) {

            LocalNotifications.schedule({
                id: 1,
                text: '¡Hora de meditar!',
                at: new Date(new Date().getTime() + 5),
                sound: 'file://audio/sound.mp3',
                every: "day",
                //data: { message : 'Informacion' },
                //icon: 'res://icon',
                //smallIcon: 'res://ic_popup_sync'
            });

            this.showSavedReminderMsg();
        } else {
            this.showNoTimePickedError();
        }

    }

saveReminder() 安排在用户按下按钮 5 秒后出现的本地通知(仅用于测试) 现在,我需要知道如何使用用户选择的日期安排此通知。

我的日期选择器,returns 一个字符串,如:“08:45”,如果存在的话,我需要任何方法来分离小时和分钟以将它们传递给调度程序,或者如何在其他一些方法中实现这一点方式。

这是用 Date.now() 解释的官方 ionic 文档: https://ionicframework.com/docs/v2/native/local-notifications/

但这不适用于我的情况。

提前致谢!

伊万.

如果您的问题是关于根据用户提供的时间创建新的 Date() 对象,您可以使用下面的方法创建自定义日期值。

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

希望这就是您要找的。

LocalNotifications.schedule({
   text: 'Delayed ILocalNotification',
   at: new Date(year, month, day, hours, minutes, seconds, milliseconds),
   led: 'FF0000',
   sound: null
});