Can a progressive web app (PWA) run a background service on a mobile device to get data from hardware (accelerometer, gps…)?

老子叫甜甜 提交于 2019-12-03 05:34:00

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!