I have this snippet:
const getCurrentPosition = () =>
new Promise<GeolocationPosition>((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(resolve, reject, {
timeout: 5000,
maximumAge: 2000,
enableHighAccuracy: true,
});
} else {
reject(new Error('Browser does not support geolocation!'));
}
});
Which I call like so:
try {
const { coords } = await getCurrentPosition();
// do stuff with coords
}
catch (e){
// handle the error
}
When executing this code in an iOS PWA (navigator.standalone
) if I have my location settings for Safari (Settings
> Privacy
> Location Services
> Safari Websites
) set to: Ask Next Time
, the getCurrentPosition()
promise hangs and does not timeout, resolve or reject. It does not prompt me for my location like it does in the iOS Safari browser
If I change the settings to Never
or While Using the App
, then it prompts me and works fine.
I want to be able to handle the scenario where a user has set their settings to Ask Next Time
whilst using a PWA.