I just implemented Local Notifications with Capacitor 3 and from what I am seeing the items that you are asking work on at least Android (emulator).
Every day at time X
This is what I am currently using. I just got it working today so haven’t confirmed that a notification continues to alert each day but they are showing up when I call getPending() after the first notification is fired. If I use Schedule.at after the notification fires, it no longer shows in getPending() as it was a one time notification.
Notifications are preserved on device restart
I cold-booted the Android virtual device and the notifications are still there when calling getPending().
Yeah I thought it was working and had similar code to that before abandoning and using Cordova and a different syntax entirely with “trigger” etc, but I’d like to use the Capacitor implementation ideally.
I would double check your results though on a device too.
Also I think that the day parameter is actually the day in the month, not of the week from my testing anyway. So if you change the date on your device/emulator after setting up a repeating notification, see if it works as expected.
Yeah I just re-tested too, still broken. Checked that issue, it’s been open for a YEAR.
A whole year and this still doesn’t work as expected.
My workaround which I’ve previously posted with the Cordova plugin and different syntax is fine.
There is an outstanding bug where if you restart the device, they get lost, so for now, I re-initialise them on app start just in case. The likelihood is that people won’t restart their phone every day so this may be almost a non issue. Just FYI.
This isn’t ideal, but is the best I can do right now until the Capacitor plugin actually works properly.
Hi,
I am having the same issue, if I schedule notification and then call the method getPending(), it returns all the notifications. But if I close and open the app and then call the method getPending(), it returns an empty array. There is any fix or this is really an annoying bug?
Make your own copy of the notification details in some JSON value/whatever suits you.
Every time you set notifications using the plugin, also update your object above in storage.
When opening the app/app init, check your own copy, if it’s there, reschedule the notifications behind the scenes without informing the user, as if it was never an issue.
I reported this plugin not working months ago and there’s no word on a fix, so I wouldn’t hold your breath.
Ok, looking at your code, a few things are unclear:
Why is there a loop?
How are you setting your day variable so that a user can choose “every Tuesday” at “14:00” or “every day” at “14:00” for example?
Do these notifications appear (without opening the app) after you change your device calendar to the future and restart the device?
If you could illustrate those points then that would help everyone here.
AFAIK, in my testing of V3, point 2 above simply still isn’t even possible with how Ionic have written their plugin. Even their docs don’t illustrate it.
Because I am setting notifications between dates, and then I calculate the diff between these dates with moment(). With that I have the number of days and I loop those.
The day is the initial Date that the user wants to set the notification, and then if I want every single day in 20 days, I just add 1 day with moment() in order to have all the dates schedule. I initially tested with the repeat, but don’t go for that, better sett a new schedule for every moment that you need! Use “at:”
I set a new notification at 16h20 when was only 16h18, and restart my device, after boot up and the 16h20 arrived, it didn’t appear the notification, but after 6 minutes, maybe 16h26 that notification came!
I think there is a delay to process the notification, I don’t know.
Never tested when changing the device calendar, because it’s not reasonable in my opinion.
If you need more example of code, I can give you
I thank you to keep this discussion because was hard for me to found some ideas or fixes at the beginning.
It is totally reasonable to change the calendar on your device and check that it works in the future.
I would recommend you do so rather than assuming that everything is fine.
You didn’t explain how you would select specifically e.g. every Wednesday at 13:00 - please show that if you can.
Off topic - moment.js has been deprecated and datefns has been the standard replacement: https://date-fns.org
Ahhh, that is a feature to do later, but I don’t have any suggestion, because we have to schedule that offline… we have to use the repeat… I don’t know… do we?
Well, thank you!! Didn’t notice that , will change!