iOS 12.2:即使在设置中手动启用后,设备方向数据仍然被阻止

iOS 12.2: device orientation data still blocked even after manual enabling in settings

使用 iOS 12.2 Apple 默认阻止访问设备方向数据。现在必须手动启用此功能 (-__-),如 here.

所述

问题是,即使在设置中启用 "Motion & Orientation Access" 后,当我尝试在 deviceorientation 事件上设置侦听器时,我在 Safari 调试器上收到了这条警告消息:

function onDeviceOrientationChange (e) {
    console.log(e)
}

window.addEventListener("deviceorientation", onDeviceOrientationChange, false);

// ---> Blocked attempt to add a device motion or orientation listener because the browsing context is not secure.

我正在 webpack dev server 上开发。我怎样才能摆脱这个障碍并像以前一样访问设备方向数据?

我最近遇到了同样的问题。事实证明,您需要启用 HTTPS 才能访问此信息。只要我启用 HTTPS,它就可以正常工作。