ServiceWorker 能否在离线的选定时间得到通知?

Can ServiceWorker be notified at selected time in offline?

说,我想在 android 上制作一个闹钟应用程序作为渐进式网络应用程序。

像原生闹钟应用一样,即使没有活动的网页,它也应该在选定的时间收到通知。

起初,我考虑过使用推送api。但是当然离线时无法到达推送消息。而且推送消息的到达时间对于闹钟来说不够准确。

是否可以在没有网络连接的情况下及时收到通知?

您所描述的是与 periodic background sync 联系更紧密的功能,而不是推送通知,因为推送通知需要网络连接。定期后台同步具有独立于网络的优势。 (定期后台同步目前只是一个提议,还没有在任何浏览器中实现。)

但是,不幸的是,对于您的用例,定期后台同步显然不是为需要在精确时间触发的事件而设计的,这将需要发出警报时钟有用。根据最初的提议:

What periodic sync is not

Periodic sync is specifically not an exact alarm API. The scheduling granularity is in milliseconds but events may be delayed from firing for several hours depending on usage frequency and device state (battery, connection, location).

The results of a sync running should be "beneficial" not "critical". If your use-case is critical, one-off syncs or the push API may serve your requirements.

现代移动操作系统中包含各种优化,以在设备被视为空闲时最大限度地减少功耗,包括 运行以交错的批次执行周期性任务,而不是对这些任务进行细粒度控制是 运行.