I'm facing an issue with sending notifications based on certain parameters. I attempted to use a combination of for loop and setTimeout in my code, but all the notifications are sent simultaneously instead of at timed intervals. The relevant snippet looks like this:
'this.times' is an array with multiple dimensions, while 'this.timer' is a variable determined by user input
for(let i of this.times) {
this.localNotification()
}
localNotification() {
setTimeout(() => {
this.date = new Date()
this.localNotifications.schedule({
text: "Hey it's time to take a picture",
trigger: {at: new Date(new Date().getTime())},
led: 'FF0000',
sound: 'file:/storage/emulated/0/media/audio/notifications/CwtChime.ogg'
})
this.notificationList.unshift({Title: "Time to take a picture", Body: "Hey, it's been a week since you took a picture, please take one", Reminder: true, Time: `${this.date.toLocaleString()}`, Seen: false})
}, this.timer*1000)
}
Unfortunately, running this code triggers all notifications at once and I'm struggling to figure out a better approach.