javascript - Can ServiceWorker be notified at selected time in offline? -
say, want make alarm clock app on android progressive web app.
like native alarm app, should notified @ selected time without active web page.
at first, considered using push api. of course push message cannot arrived while offline. , push message arrival time cannot accurate enough alarm clock.
is possible notified @ time without network connection?
what you're describing functionality that's more closely tied periodic background sync, rather push notifications, in push notifications require network connection. periodic background sync has advantage of being network-independent. (periodic background sync proposal right now, , hasn't been implemented in browsers.)
but, unfortunately use case, periodic background sync explicitly not designed events need triggered @ precise time, needed make alarm clock useful. that's explicitly called out in proposal:
what periodic sync not
periodic sync not exact alarm api. scheduling granularity in milliseconds events may delayed firing several hours depending on usage frequency , device state (battery, connection, location).
the results of sync running should "beneficial" not "critical". if use-case critical, one-off syncs or push api may serve requirements.
there various optimizations baked modern mobile operating systems minimize power usage when device considered idle, including running periodic tasks in staggered batches instead of given tasks fine-grained control on when they're run.
Comments
Post a Comment