Javascript DeviceOrientationEvent.askPermission()未提示任何内容

Javascript DeviceOrientationEvent.askPermission()未提示任何内容,javascript,accelerometer,ios13,mobile-website,device-orientation,Javascript,Accelerometer,Ios13,Mobile Website,Device Orientation,我想通过电话访问加速计数据 在iOS 13中,您必须明确请求获得该数据的许可 我的开发安装程序正在运行webpack dev server,使用--https,在我的iPhone(iOS 13.3,Safari)上的本地网络上进行测试 我第一次调用checkOrientation()-当它在iOS上时返回true(例如,我的桌面客户端返回false) 如果checkOrientation()返回true,我将调用askOrientation()。此承诺调用DeviceOrientationEve

我想通过电话访问加速计数据

在iOS 13中,您必须明确请求获得该数据的许可

我的开发安装程序正在运行
webpack dev server
,使用
--https
,在我的iPhone(iOS 13.3,Safari)上的本地网络上进行测试

  • 我第一次调用
    checkOrientation()
    -当它在iOS上时返回
    true
    (例如,我的桌面客户端返回
    false
  • 如果
    checkOrientation()
    返回
    true
    ,我将调用
    askOrientation()
    。此承诺调用
    DeviceOrientationEvent.requestPermission()
    方法,然后
    if(response==“grated”)返回true然后调用
    
    window.addEventListener(“deviceorientation”,handleOrientation,true)
  • 在MobileSafari上,我得到了来自Promise的响应,但我在控制台中得到一个错误:
    DomeException{}
    ,没有更多信息。response=='grated'返回false,但在此之前我从未得到任何提示

    以下是大部分代码:

    exports.checkOrientation = function(){
          console.log("PermissionsMgr asking Orientation");
          if(typeof(DeviceOrientationEvent) !== 'undefined' && typeof (DeviceOrientationEvent.requestPermission) === 'function'){
            //ios13
            return true;
          }else{
            // not ios13
            return false;
          }
        }
    
    //如果checkOrientation()==true,那么我调用askOrientation():


    问题:当我调用DeviceOrientationEvent.requestPermission()时,如何在我的移动设备上显示提示?

    您是否设法修复了它?
    exports.askOrientation = function(){
        DeviceOrientationEvent.requestPermission()
            .then(response => {
                if(response=='granted'){
                    hasGranted=true;
                }else{
                    hasGranted=false;
                }
                return hasGranted;
            })
            .catch(console.error)
    }