navigator.permissions.query Permissions API是否有替代方法? [英] Is there any alternative to navigator.permissions.query Permissions API?
问题描述
除了navigator.permissions.query
权限API 查询以检查geolocation
权限.
导致其仍在工作草案中,并且浏览器兼容性较低.
W3C权限参考: https://www.w3.org/TR/permissions/
一旦用户在本机权限弹出窗口上执行了操作,然后要检查用户正在使用的action
,问题就为app resume
.
平台:移动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屋!