开发者工具地址授权点击授权之后,调用获取授权信息接口返回并未授权
发布于 6 年前 作者 mqiao 10265 次浏览 来自 问答

调用wx.getSetting 授权API时返回的值

点击允许之后 authSetting 依旧没有发生改变

但是真机 这么操作之后

正常返回结果

1 回复

以下代码片段仅供参考:

wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
          wx.openSetting({
            success: function (res) {
              if (res.authSetting["scope.userLocation"] == true) {
                wx.showToast({
                  title: '授权成功',
                  icon: 'success',
                  duration: 1000
                })
                wx.getLocation({
                  type: 'wgs84',
                  success: function (res) {
                    console.log('地理位置', res)
                  }
                })
              }
            }
          })
        } else if (res.authSetting['scope.userLocation'] == undefined) {
          wx.getLocation({
            type: 'wgs84',
            success: function (res) {
              console.log('地理位置',res)
            }
          })
        }
      }
    })
  }
回到顶部