Could you tell me how to do local notification correctly?
I’m using Local Notifications plugin.I need to trigger the notification at 10.01 AM every day. I have used below code. It is working fine when I tested on the same day at a different time.Let’s say 16H 5Min. But it is not working automatically for the next day. I can guarantee that all the data are there for the next data. But it seems I have done something wrong here. Please tell me where is the error?
app.component.ts
constructor(){
this.initializeApp();
}
initializeApp() {
try {
this.platform.ready().then(() => {
timer(60000, 60000).subscribe(val => {
const hours = moment().format("H");
const minutes = moment().format("m");
if (hours == '10' && minutes == '1')
this.scheduleNotification();
});
});
}
catch (err) {
console.log(err);
}
}
scheduleNotification() {
let firstNotificationTime = new Date();
firstNotificationTime.setDate(firstNotificationTime.getDate());
firstNotificationTime.setHours(10);
firstNotificationTime.setMinutes(1);
firstNotificationTime.setSeconds(0);
forEach(this.authenticationProvider.member.projects, (project: Project) => {
forEach(project.transactions, (transaction: Transaction) => {
if (transaction.dueOn != null && moment(transaction.dueOn).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD')) {
const id = random(1, 1000);
this.localNotifications.schedule({
id: id,
title: 'Due Today',
text: `Payment for ${transaction.category.name}: ${transaction.description} of ${Number(transaction.totalPrice).toLocaleString()} is due today.`,
data: { transaction: transaction, project: project },
at: firstNotificationTime,
});
}
});
});
}