openMap: function () { wx.getSetting({ success: (res) => { let locationAuth = res.authSetting[ 'scope.userLocation' ] if (!locationAuth) { wx.authorize({ scope: 'scope.userLocation' , success: (res) => { wx.navigateTo({ url: '/pages/map/map' , }) }, fail: (res) => { wx.showModal({ title: '需要地理位置授权' , content: '' , confirmText: this .data.authBtnText, success: (res) => { if (res.confirm) { wx.openSetting({ }) } } }) } }) } else { wx.navigateTo({ url: '/pages/map/map' , }) } } }) } |
按照新规则使用 bindtap='openMap' 触发授权,wx.showModal() 放在 wx.authorize() 外面可以通过 confirm 回调成功调用 wx.openSetting() 呼出设置页面,但是如上面的代码一样放在 wx.authorize() 的 fail 回调分支中的话,则在开发工具中调用 wx.openSetting() 无响应,但在手机端仍然可正常呼出设置页面