In iOS 13 Apple has introduced the API DeviceOrientationEvent.requestPermission. It must be triggered on user action (click, tap or equivalent). My problem here is that the result seems to be cached, so in case the user denies permission I can't ask access again (the promise is automatically fulfilled with the cached value). Is there any way to force the device to forgot the cached value and ask again for the user permission to access orientation data (I mean it should display again the popup window where the user can allow or deny access)?
This is the relevant code:
if (DeviceOrientationEvent && typeof(DeviceOrientationEvent.requestPermission) === "function") {
const permissionState = await DeviceOrientationEvent.requestPermission();
if (permissionState === "granted") {
// Permission granted
} else {
// Permission denied
}
}
In iOS 13 Apple has introduced the API DeviceOrientationEvent.requestPermission. It must be triggered on user action (click, tap or equivalent). My problem here is that the result seems to be cached, so in case the user denies permission I can't ask access again (the promise is automatically fulfilled with the cached value). Is there any way to force the device to forgot the cached value and ask again for the user permission to access orientation data (I mean it should display again the popup window where the user can allow or deny access)?
This is the relevant code:
if (DeviceOrientationEvent && typeof(DeviceOrientationEvent.requestPermission) === "function") {
const permissionState = await DeviceOrientationEvent.requestPermission();
if (permissionState === "granted") {
// Permission granted
} else {
// Permission denied
}
}
Share
Improve this question
asked Sep 24, 2019 at 16:35
revyrevy
4,72711 gold badges48 silver badges101 bronze badges
4 Answers
Reset to default 4Try simply to quit Safari and launch it back. The prompt will e back.
I see the same behavior on iOS 13 Safari. You need to remove the website data for the particular site that needs permission. Go to Settings > Safari > Advanced > Website data, lookup the site and remove all the data. Then the prompt should show up again when you ask for permission.
Are you sure it's a caching issue? I cannot get incognito Safari in iOS 13 to respond with a "granted" permission. I'm getting a "denied" response immediately - no prompt.
I'm using the following code to test the result, but it's always "denied" immediately without a prompt event showing. (https://codepen.io/ejarnutowski/pen/WNePqmM)
<button onclick="testDeviceOrientation()">Test Device Orientation</button>
function testDeviceOrientation() {
if (typeof DeviceOrientationEvent !== 'function') {
return setResult('DeviceOrientationEvent not detected')
}
if (typeof DeviceOrientationEvent.requestPermission !== 'function') {
return setResult('DeviceOrientationEvent.requestPermission not detected')
}
DeviceOrientationEvent.requestPermission().then(function(result) {
return setResult(result);
});
}
function setResult(result) {
document.getElementById('result').innerHTML = 'RESULT: ' + result;
}
Looks like drawmote.app has this working but the JS is piled and it's taking me a while to reverse engineer their logic.
Redirect it to another subdomain that points to the same page.