Can a progressive web app (PWA) run a background s

2019-04-06 04:13发布

I see we can check the capabilities of a mobile browser using https://whatwebcando.today/, but can the hardware APIs be queried when not running on foreground?

I mean... With PWA am I able to build an app that gets hardware info while running in background, just like Octo U, for Android, and posts that info to a web server?

2条回答
Root(大扎)
2楼-- · 2019-04-06 04:52

service workers run on an event driven model. This means they only spin up when registered events (browser UI making a network request, push notification and background sync for now). What I think you are asking for is geo-fenching capabilities. AFAIK this is something being discussed to add to the SW model. If not it should be because it would be very valuable for marketing purposes. I know it is being used in native apps, so I think it would be on the radar. GPS is accessible from the front-end and has been for years in the browser. However the user would need to have your site/PWA loaded in the browser.

查看更多
叛逆
3楼-- · 2019-04-06 04:56

The modern method of running code "in the background" is by using a service worker, either via its push event handler (triggered via an incoming push message), or via its sync event handler (triggered by an automatic replay of a task that previously failed).

It's not currently possible to access the type of hardware sensors that you're asking about from inside a service worker.

查看更多
登录 后发表回答