api权限_权限API

api权限

Many of the functionalities that we're translated from mobile to the web require permission from the user.  Think about geolocation, audio/video access (think getUserMedia for camera access), and likewise APIs.  We can probably all agree that requiring permission for access to these APIs is a good thing, but I see a problem:  there's sometimes no way to access each APIs permission level without triggering a request to the user to get that information.  Obtrusive to say the least!

我们从手机到网络的许多功能都需要得到用户的许可。 考虑一下地理位置,音频/视频访问( 对于摄像头访问 ,请考虑使用getUserMedia ),以及类似的API。 我们可能都同意,要求获得对这些API的访问权限是一件好事,但我看到一个问题:有时,在不触发用户获取该信息的请求的情况下,无法访问每个API的权限级别。 至少可以这么说!

I recently discovered the Permissions API which provides a method to query the permission level for an API without trigger a request to the user for access.  Let's look at a simple example:

最近,我发现了Permissions API ,它提供了一种查询API权限级别的方法,而无需触发用户访问请求。 让我们看一个简单的例子:

// Get the geolocation status (starts out as "prompt")
// ... meaning the user will be shown an access request if we want it
navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "prompt" */
});

// Request geolocation access if we really want it
navigator.geolocation.getCurrentPosition(function(result) { /* ... */  })

// Assuming the user requested access, the permission is now "granted"
navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "granted" */
});

// Push notifications require options:
navigator.permissions.query({ name: 'push', userVisibleOnly:true }).then(function(result) { /* ... */ });


I love this new API -- a clear path for getting a permission level without needing to request any information from the user. For example: if the permission level is negative, don't ask the user permission to do something, or prompt the user in another fashion to allow a given permission.

我喜欢这个新的API,这是获取权限级别的清晰路径,而无需从用户那里请求任何信息。 例如:如果权限级别为负,则不要要求用户权限做某事,也不要以其他方式提示用户允许给定权限。

Do you see another advantage to this API? Share!

您看到此API的另一个优势了吗? 分享!

翻译自: https://davidwalsh.name/permissions-api

api权限

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值