ios 13 DeviceOrientationEvent.requestPermission:如何强制设备再次询问用户权限

rev*_*evy 6 javascript device-orientation ios

在 iOS 13 中,Apple 引入了 API DeviceOrientationEvent.requestPermission。它必须由用户操作(单击、点击或等效操作)触发。我的问题是结果似乎被缓存了,所以如果用户拒绝许可,我不能再次请求访问(使用缓存值自动实现承诺)。有什么方法可以强制设备忘记缓存的值并再次请求用户访问方向数据的权限(我的意思是它应该再次显示用户可以允许或拒绝访问的弹出窗口)?

这是相关代码:

if (DeviceOrientationEvent && typeof(DeviceOrientationEvent.requestPermission) === "function") {
    const permissionState = await DeviceOrientationEvent.requestPermission();

    if (permissionState === "granted") {
        // Permission granted    
    } else {
        // Permission denied
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 0

您确定这是缓存问题吗?我无法让 iOS 13 中的隐身 Safari 响应“已授予”权限。我立即收到“拒绝”回复 - 没有任何提示。

我正在使用以下代码来测试结果,但它总是立即“拒绝”,而没有显示提示事件。(https://codepen.io/ejarnutowski/pen/WNePqmM

<button onclick="testDeviceOrientation()">Test Device Orientation</button>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)

看起来 drawmote.app 可以正常工作,但是 JS 已编译,我需要一段时间才能对其逻辑进行逆向工程。