我正在使用ionic 3中的localnotifications插件来获取通知。我想每天在特定时间触发通知。就像用户在今天上午10:00设置提醒一样,它应该在每天的同一时间自动触发,直到用户下次更新提醒为止。
我已经尝试了以下代码来实现它,但是它不起作用。
morningTime: String = '08:15';
date: any = '';
scheduleMorningReminder(){
this.date = this.datePipe.transform(this.date,"yyyy-MM-dd");
var reminder_date = new Date(this.date+" "+this.morningTime);
if(reminder_date){
this.localNotifications.schedule({
text: 'This is your notification',
trigger: {at: reminder_date},
led: 'FF0000',
id: 1,
every: 'day'
});
}
}
我的html
<ion-datetime displayFormat="hh:mm A" pickerFormat="h mm A" [(ngModel)]="morningTime" (ionChange)="scheduleMorningReminder()"></ion-datetime>
我也尝试了以下代码
scheduleMorningReminder(){
this.date = this.datePipe.transform(this.date,"yyyy-MM-dd");
var reminder_date = new Date(this.date+" "+this.morningTime);
var hours = reminder_date.getHours();
var minutes = reminder_date.getMinutes();
var pushTime = moment().add(0, 'days').hours(hours).minutes(minutes).seconds(0);
if(reminder_date){
this.localNotifications.schedule({
text: 'This is your notification',
trigger: {at: pushTime.toDate()},
led: 'FF0000',
id: 1,
every: 'day'
});
}
}
有人可以帮我吗?