检测是否有运动和在Javascript中启用了定向访问-iOS [英] Detect whether Motion & Orientation Access is enabled in Javascript - iOS

查看:106
本文介绍了检测是否有运动和在Javascript中启用了定向访问-iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,默认情况下,Safari会禁用运动和方向"访问:

设置> Safari>隐私&安全>运动与安全定向访问

所以我要弄清楚的是,是否有可能检测用户是否启用了此设置.浏览器中的窗口对象上是否有一个属性可以通知我该属性已启用?

我尝试在StackOverflow和其他地方查找解决方案,但它们要么过时,要么就不起作用.

解决方案

您可以使用 window.orientation 属性(输出将以度为单位),因为Safari for IOS支持该属性

注意:它的使用已被弃用,并且在许多其他浏览器中不受支持,在其他浏览器中,您应使用 screen.orientation 属性或通用传感器API

Unfortunately Safari disables Motion and Orientation access by default in:

Settings > Safari > Privacy & Security > Motion & Orientation Access

So what I'm trying to figure out is if it's possible to detect whether the user has this setting enabled or not. Is there a property on the window object in the browser that informs me that it's enabled?

I've tried looking up the solution on StackOverflow and various other places but they're either outdated or just don't work.

解决方案

You could use the window.orientation property (output will be in degrees), since it is supported in Safari for IOS

Note: Its use is depreciated and is not supported in many of the other browsers, fore other browsers you should use the screen.orientation property or the Generic Sensors API

这篇关于检测是否有运动和在Javascript中启用了定向访问-iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆