2

I would like to schedule a Local Notification every day at a particular time. According to capacitor docs https://capacitorjs.com/docs/apis/local-notifications I have implemented it, the following pattern.

LocalNotifications.schedule({
  notifications: [
 {
   id: 1,
   title: 'Test local notification',
   body: "Lorem ipsum",
   schedule: { on: { hour: 9, minute: 9}, allowWhileIdle: true, every: 'day' }
  }
})

This implementation is not working currently probably because of "on" and "every" options chosen together, which I am not sure of. Any guidance or implementation is much appreciated

Harsh Nagarkar
  • 697
  • 7
  • 23

2 Answers2

0

same problem here... To avoid the issue i create all the notifications one by one at the start of the app... (if there is no or less than 10notifications pending)

async setMonthNotif(){
    for(let day=0; day <= 30; day++){
        let date: Date = new Date();
        date.setDate(new Date().getDate()+day);
        await this.setNotif(date);
     }
   }

async setNotif(datePrevue?: Date){
 let randomId = Math.floor(Math.random() * 10000) + 1;

 // i need it every day at 9:25
 const date = datePrevue? datePrevue : new Date();
 date.setHours(9);
 date.setMinutes(25);

 // if time already pass
 if(date > new Date()){
   await LocalNotifications.schedule({notifications: [{
     title: 'Trade disponible !',
     body: 'Le trade du jour est maintenant disponible',
     id: randomId,
     schedule: {
       at : date,
       allowWhileIdle: true
     },
   }]})
 }
0

For me, this example works great. Just set the time at which you want to display the notification and that's it. In this example, I display a notification every day at 12:00 a.m.

schedule: {
  allowWhileIdle: true,
  on: {
    hour: 12,
    minute: 0
  }
}
senior_script
  • 111
  • 1
  • 10