小程序调用wx.chooseLocation接口的时候无法获取权限(ios)

ios手机小程序调用wx.chooseLocation接口的时候,获取权限的时候报authorize:fail:require permission desc这样子的错误,这是由于苹果的安全机制导致需要再app.json加上

"permission": {
    "scope.userLocation": {
      "desc": "您的位置信息将用于添加收货地址"
    }
  }

但有时还是无法获取授权,则需要在使用的地方判断是否授权,没有的话则再次提醒用户授权

chooseLocation:function(){
    let _this = this;
    wx.chooseLocation({
      success(e){
        _this.setData({
          map: e.longitude + ',' + e.latitude,
          addr: e.address
        })
      },
      fail(e){
        wx.showToast({
          title: e.errMsg,
          icon:'none'
        })
      }
    })
  },
  getLocation:function(){
    let _this = this;
    wx.getSetting({
      success(res) {
        // 判断定位的授权
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              _this.chooseLocation();
            },
            fail(errMsg) {
              wx.showToast({ title: JSON.stringify(errMsg), icon: 'none' }) 
            }
          })
        } else {
          _this.chooseLocation();
        }
      }
    })
  },
原文地址:https://www.cnblogs.com/lhj-blog/p/11163872.html