admin管理员组文章数量:1245127
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.
本文标签:
版权声明:本文标题:javascript - ios 13 DeviceOrientationEvent.requestPermission: how to force device to ask again for user permission - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740149878a2232459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论