背景
开发vr全景展现的功能,需要申请陀螺仪的权限,但是在浏览器里测试是却报错了,查了一下属性的兼容性发现没有问题。
image.png解决
新开了一个标签页,在控制器里输出 DeviceOrientationEvent
发现是个正常的function。 但是自己的页面就是不行,突然发现本地起来页面是用http的协议,部署到测试环境使用https,发现不会报错,猜测报错和安全协议有关。本地使用 localhost
也是可以的。
Because Generic Sensor API is a powerful feature, Chrome only allows it on secure contexts. In practice it means that to use Generic Sensor API you'll need to access your page through HTTPS. During development you can do so via http://localhost but for production you'll need to have HTTPS on your server. See Security with HTTPS article for best practices and guidelines there.
网友评论