I know you can send push notifications to a user who has installed the pwa. However, this always requires a server which sends that notification and also the end user device to be online to recieve and show it.
I was wondering if there is a way to "schedule" a push notification to be shown later, like it is possible on Android to be able to realize something like reminders for events, without the need to have an internet connections.
EDIT: Since Chrome 80, notification triggers are available as an origin trial.
I know you can send push notifications to a user who has installed the pwa. However, this always requires a server which sends that notification and also the end user device to be online to recieve and show it.
I was wondering if there is a way to "schedule" a push notification to be shown later, like it is possible on Android to be able to realize something like reminders for events, without the need to have an internet connections.
EDIT: Since Chrome 80, notification triggers are available as an origin trial.
Share Improve this question edited Feb 24, 2020 at 19:00 kolaente asked Jun 3, 2019 at 18:05 kolaentekolaente 1,30211 silver badges25 bronze badges 4- 3 How are you planning to get the data to be scheduled in first place? – karthick Commented Jun 3, 2019 at 18:32
- 2 Something like this: I build a website which shows events (for a conference for ex) as a pwa, so when the user visits the site, it downloads all events. These are stored offline. After this point, an internet connection should not be needed anymore. The user can then select events to get notfications for, put them in a list with favourites, whatever. When he chooses to get notified for a particular event, the notification to something like 5min before the event is scheduled and then shown when it was scheduled. – kolaente Commented Jun 3, 2019 at 18:56
- My idea about this is background sync API... wondering if anybody managed to implement this with it. But I think it's possible! – mr.alex Commented Jun 3, 2019 at 20:42
- I think it may be too unpredictable if running in the background. One option is to build something that allows the users to push reminders to THEIR calendar for the events that matter to them. Use the wheel that has already been built on every device. IMHO – Mathias Commented Jun 3, 2019 at 21:47
2 Answers
Reset to default 31There are at least 3 web APIs/specs in the development related to some form of the scheduled tasks. None of them are in production though.
Periodic Background Sync API
- Explainer: https://github.com/beverloo/periodic-background-sync
- Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=925297
- Status: https://www.chromestatus.com/feature/5689383275462656 (in dev)
Main feature: it enables a web app to run tasks periodically while the device has network connectivity
Notification Triggers (a.k.a. Scheduled Notification API / Event Alarms)
- Explainer: https://github.com/beverloo/notification-triggers
- Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=891339
- Status: https://www.chromestatus.com/feature/5133150283890688 (proposed, part of Project Fugu)
Main feature: this allows to show a notification (nothing else) reliably at a specific time in the future, even if the device is offline
Scheduled Task API (Generic Alarms)
- Explainer: internal design docs only
- Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=889077
- Status: TBD, part of Project Fugu
Main feature: schedule code to run at a specified time in the future - cron for the Web
So answering the original question: your choice is Notification Triggers API. Hopefully this will land in the browsers soon.
At the time of writing (November 2024), periodic-sync is supported by Chrome (both on desktop and on Android) and Edge, as well as a few other platforms. Unfortunately no support for Safari or Firefox. (I don't think iOS will ever want to support something like periodic-sync, because it's my understanding that they want people to publish native apps in their app store)
I've tested periodic-sync myself on Chrome for Android and Chrome for Desktop, and it works. Unfortunately I haven't found a real alternative for the other platforms (maybe using setTimeout could work in some cases but it requires the app to be open)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1738197849a4030188.html
评论列表(0条)