微信小程序一次性让用户授权多个权限

可以通过wx.authorize 配合 wx.getSetting 使用,一次性让用户授权多个权限。

代码:

<view catchtap="authorize">获取多个授权</view>
  authorize(){
    // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.record']) {
          wx.authorize({
            scope: 'scope.record',
            success() {
              // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
              wx.startRecord()
            }
          })
        }
        if (!res.authSetting['scope.address']) {
          wx.authorize({
            scope: 'scope.address',
            success() {
              wx.chooseAddress({
                success(res) {
                  console.log('3333333',res)
                }
              })
            }
          })
        }
      }
    })
  },
发布了387 篇原创文章 · 获赞 774 · 访问量 183万+

猜你喜欢

转载自blog.csdn.net/qq_35713752/article/details/103522401