iOS PWA location access prompt not showing

Viewed 323

I have built a PWA that calls the javascript API navigator.geolocation.getCurrentPosition which prompts the user for location access when the Safari permission is set to Ask. This is the correct behavior and works as expected when open in Safari.

However when added to the Home Screen and running with a display mode of "standalone", the location alert does not open on my phone (iPhone 13 mini / iOS 15.1.1). And the call never times out. Then if I switch from the PWA to Safari the location alert / prompt is suddenly showing in Safari. So it seems that the alert is targeting the wrong "tab". This does not happen if the PWA display mode is "browser" or "mimimal-ui" with either of those it behaves normally.

I can only replicate this on my phone (iPhone 13 mini / iOS 15.1.1). I have also tested on various older phones (15.1.1 and 14.7) as well as several emulators and they all behave as expected. It is possible this is a obscure setting on my phone but it does feel a lot like an iOS Safari bug.

1 Answers

I also faced this issue using an iPad in iOS 15.5. My application is a webapp running on Safari mobile added to the home screen. The exact same happens in display standalone and fullscreen, not in minimal-ui or browser: the prompt is shown either for the first time ever when the website needs location permission or Location Services -> Safari Webistes is on "Ask Next Time or When I Share". "While Using the App" works fine.

To overcome the problem, I race navigator.geolocation.getCurrentPosition against a setTimeout a bit longer than PositionOptions.timeout. If the latter wins the race, it means that we detected this situation and I can throw some custom error there to inform the user about what happened and what to do (Change Location Services -> Safari Webistes manually).

Related