小程序获取位置授权的问题
发布于 6 年前 作者 bzhu 2539 次浏览 来自 问答

一个项目需要在用户打开小程序后,先进行位置和用户信息的授权检测,只有用户同意两个授权后才能进入小程序内。但是在测试的过程中,发现在获取位置授权时,有些时候位置授权的提示总是不出来,即选择“是”或者“否”的选择页面没有跳出。所以在接下来的授权检测里,就无法再次进行位置授权的操作了。因为openSetting打开时,根本没有位置授权的选项,以下是我的两种写法,均无法完美的解决问题,所以想问wx.getLocation()方法到底是怎么回事。

if (res.authSetting['scope.userInfo'] &&  res.authSetting['scope.userLocation']){
    //已经有了权限,进行登陆,跳转主页
    getApp().getUserInfo();
    wx.switchTab({
       url: '../index/index',
    })
 }else{
    //获取位置权限
    wx.getLocation({})
    if (that.data.flag) {
      wx.showLoading({
        title: '获取权限中',
      })
      //自己写的一个线程休眠方法,为了不让用户信息授权先出来
      that.sleep(1000)
      wx.getUserInfo({
        complete: function (res) {
        //执行后续的权限检查操作
          that.check();
        }
     })
   }
 }
}

if (res.authSetting['scope.userInfo'] &&  res.authSetting['scope.userLocation']){
    //已经有了权限,进行登陆,跳转主页
    getApp().getUserInfo();
    wx.switchTab({
       url: '../index/index',
    })
 }else{
    if (that.data.flag) {
      wx.showLoading({
        title: '获取权限中',
      })

      //获取位置权限

      wx.getLocation({

         complete: function (res) {

             //在位置授权回调内调用用户权限

             wx.getUserInfo({
                complete: function (res) {
                  //执行后续的权限检查操作
                  that.check();
                }
             })

         }

      })

   }
 }
}

1 回复

我感觉这个问题类似于二次授权。http://mp.weixin.qq.com/debug/wxadoc/dev/api/setting.html  或者百度一下 微信小程序二次授权。希望有帮助QAQ。

回到顶部