[英]How to check motion/orientation permissionState in iOS.12.2+ by Javascript?
With iOS12.2+ Apple wants a user gesture to activate devicemotion or deviceorientation.在 iOS12.2+ 中,Apple 希望通过用户手势来激活 devicemotion 或 deviceorientation。 I have found samples in the Internet, fe here .我在互联网上找到了样本,fe here 。 I show a popup window in which the user will be informed and can accept or deny the access.我会显示一个弹出窗口,用户将在其中收到通知并可以接受或拒绝访问。 This is all working fine with Javascript.这一切都适用于 Javascript。
I'm aware Safari is caching the permissionState (granted or denied), so after giving or denying permission (by user) the page can be reloaded and the permissionState is still known.我知道 Safari 正在缓存权限状态(授予或拒绝),因此在授予或拒绝权限(由用户)后,页面可以重新加载,并且权限状态仍然是已知的。 Here comes the problem: (how) can I check if the permission is already granted or denied?问题来了:(如何)我可以检查权限是否已被授予或拒绝? In case it's already set I don't want to display the popup (asking for permission) again after page reload.如果它已经设置,我不想在页面重新加载后再次显示弹出窗口(请求许可)。
okay, I think I found a solution, it's not pretty but it works.好吧,我想我找到了一个解决方案,它不是很好,但它有效。
First I have a function that checks if iOS 13+ if that's the case, I then request permissions, turns out if the user has already granted access DeviceMotionEvent.requestPermission returns granted if they haven't granted access it fails, and then I trigger the modal.首先我有一个函数来检查 iOS 13+ 是否是这种情况,然后我请求权限,如果用户已经授予访问权限DeviceMotionEvent.requestPermission返回授予如果他们没有授予访问权限失败,然后我触发模态。 To then ask for permissions again.然后再次请求权限。
DeviceMotionEvent.requestPermission()
.then(response => {
if (response) {
console.log(response)
}
})
.catch(function(error) {
console.log("error");
// Trigger modal to ask for permissions
$('#askForPermission').modal('toggle')
});
hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.