navigator.permissions.query Permissions API是否有替代方法? [英] Is there any alternative to navigator.permissions.query Permissions API?

查看:443
本文介绍了navigator.permissions.query Permissions API是否有替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了navigator.permissions.query 权限API 查询以检查geolocation权限. 导致其仍在工作草案中,并且浏览器兼容性较低.

W3C权限参考: https://www.w3.org/TR/permissions/

一旦用户在本机权限弹出窗口上执行了操作,然后要检查用户正在使用的action,问题就为app resume.

用于位置许可警报的混合Cordova应用回调

平台:移动Android

注意:不想使用cordova diagnostic plugin

示例:

navigator.permissions.query({name:'geolocation'}).then(function(result) {

  console.log('result : ', result);

});

解决方案

我不这么认为.

此刻,navigator.permissions对象尚未定义-可能出于有意将其在WebView中删除的目的是不将Web权限与Android权限混合使用.

选项1:

您可以尝试 Cordova诊断插件,尤其是应该使用的getLocationAuthorizationStatus方法返回权限状态的方式与Permissions API非常相似. 请注意,我还没有尝试过该插件.

选项2:

通过请求位置来触发位置许可对话框. 当您收到带有PERMISSION_DENIED常量代码的 PositionError 时,这意味着用户拒绝了位置权限(仅在现在或在应用设置下).

navigator.getCurrentPosition(
  function(position) { /** won't be executed for such short timeout */ },
  function(positionError) {
    switch (positionError.code) {
    // PERMISSION_DENIED
    case 1:
      console.log('Permission denied')
      break
    // POSITION_UNAVAILABLE
    case 2:
      console.log('Permission allowed, location disabled')
      break
    // TIMEOUT
    case 3:
      console.log('Permission allowed, timeout reached')
      break
    }
  },
  {timeout: 0}
)

Is there any alternative to navigator.permissions.query Permissions API query to check geolocation permission. cause its still in Working Draft and has less Browser compatibility.

W3C Permissions Ref : https://www.w3.org/TR/permissions/

Issue is app resume once user perform action on native permission popup then wanted to check the action being taken by user.

Hybrid Cordova App callback for location permission alert

Platform : Mobile Android

NOTE : Don't want to use cordova diagnostic plugin

Example:

navigator.permissions.query({name:'geolocation'}).then(function(result) {

  console.log('result : ', result);

});

解决方案

I don't think so.

At this moment the navigator.permissions object is undefined - probably it's removed in WebView by purpose to not mix web permissions with android permissions.

Option 1:

You may try Cordova diagnostic plugin, specifically the getLocationAuthorizationStatus method which should return permission state in very similar way to Permissions API. Please note I haven't tried the plugin.

Option 2:

Trigger location permissions dialog by requesting location. When you'll receive PositionError with PERMISSION_DENIED constant code, it'll mean that user denied location permission (just now or at app settings).

navigator.getCurrentPosition(
  function(position) { /** won't be executed for such short timeout */ },
  function(positionError) {
    switch (positionError.code) {
    // PERMISSION_DENIED
    case 1:
      console.log('Permission denied')
      break
    // POSITION_UNAVAILABLE
    case 2:
      console.log('Permission allowed, location disabled')
      break
    // TIMEOUT
    case 3:
      console.log('Permission allowed, timeout reached')
      break
    }
  },
  {timeout: 0}
)

这篇关于navigator.permissions.query Permissions API是否有替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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