微信小程序 camera组件当调用wx.openSetting手动打开授权后,camera组件不生效

77 阅读1分钟

解决方案: <camera mode="normal" device-position="back" frame-size="small" binderror="onError" style="height: 70vh;width: 100%;" resolution="medium"> 监听binderror事件 在事件内执行以下方法

    wx.showModal({
      title: '提示',
      content: '尚无相机权限,前往授权?',
      success :(res)=> {
        if (res.confirm) {
          wx.openSetting({
            success:(res)=>{
              if (res.authSetting["scope.camera"]) {
                  wx.redirectTo({
                    url: 'xxx' // 重新刷新一下当前页面就直接重新执行了
                  })
                }
            }
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })