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();
}
}
})
},