Posts

Post not yet marked as solved
5 Replies
6.0k Views
Hello thereWith iOS12.2+ Apple changed the way to access DeviceOrientation and DeviceMotion in Safari: The user must first do any gesture (click button, swipe, etc.) in order to get asked if he wants to allow DeviceOrientation or DeviceMotion. In my Web-App (Javascript) I want the user to be able to locate himself on a map (GPS located game). It's fine Apple implemented more security for the user. I've found a code snipped that I made working and that will be executed when the user presses a specific button "Request Orientation" (user gesture):function requestDeviceOrientation () { if (typeof DeviceOrientationEvent !== 'undefined' && typeof DeviceOrientationEvent.requestPermission === 'function') { DeviceOrientationEvent.requestPermission() .then(permissionState => { if (permissionState === 'granted') { window.addEventListener('deviceorientation', () => {}); } }) .catch(console.error); } else { // handle regular non iOS 13+ devices console.log ("not iOS"); } }It seems that the Safari browser caches the users answer on this (granted, denied). On reloading the page the permission (granted, denied) is still cached. In such a case it makes no sense to display the request button again. So therefore I need to know if the permission was already granted or not in order to display the button (or not). So far I don't see any possiblity how to check if the permission is already set or not (f.e. in the ready function after loading page). That way I'm forced to always display the button "Request Orientation" whether the permission is already given or not.It looks like to me that the Safari developers were not thinking to the end here. So my question is: Anyone knows how I can check if the permission is already set (granted, denied)?Thank you!
Posted
by tygoesmac.
Last updated
.