小程序調用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();
        }
      }
    })
  },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM