自iOS 11起,我使用devicemotion事件在Safari上访问陀螺仪。
历史:
问题:
在iOS 13.4上,并且我使用此功能的所有项目都没有代码更改,即使用户同意陀螺仪访问,rotationRate始终为null。
我从Apple搜寻了官方的答案,但没有资料。
它看起来像个错误,但也许我这边的实现是错误的?
很高兴知道我的代码:
首先,我监听devicemotion事件(rotationRate为null),当界面准备就绪时,用户单击按钮,要求陀螺仪访问,并且rotationRate具有值。
有任何想法吗 ?
最佳答案
这似乎是iOS 13.4中的错误,因为即使webxr polyfill也无法检测到设备具有的功能,因为它们具有(第3770行):
if (this.isWithoutDeviceMotion) {
window.addEventListener('deviceorientation', this.onDeviceOrientationCallback_);
} else {
window.addEventListener('devicemotion', this.onDeviceMotionCallback_);
}
条件评估为false,因此使用devicemotion,然后
rotationRate
和accelerationIncludingGravity
均为空。因此,我认为从现在开始的解决方法是监听deviceorientation事件,而不是devicemotion,即使事先已经请求了权限,这还是必须的。
关于javascript - 在iOS 13.4上deviceMotion rotationRate为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61339598/