收藏
回答

uni.openSetting打开设置,里面没有位置信息授权?

使用wx.authorize获取用户位置信息,用户拒绝授权后使用wx.openSetting引导用户打开设置,但是设置里面没有位置信息授权。这种要怎么处理?

回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2024-08-06

    请提供能复现问题的原生简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2024-08-06
    有用
    回复 1
    • 一只小花猫
      一只小花猫
      2025-12-17
      const getAuthRize = ()=>{
        return new Promise((resolve,reject)=>{
          uni.authorize({
            scope: 'scope.userLocation',
            success: (result)=>{
              resolve(result)
            },
            fail: ()=>{
              reject('授权失败')
            },
          });
        })
      }


      const getLocalFail = ()=>{ 
        uni.showModal({
          title: '提示',
          content: '需要获取您的地理位置,请前往设置打开位置权限',
          success: (res)=>{
            if(res.confirm){
              uni.openSetting({
                success: (res)=>{
                  console.log('打开设置成功',res)
                },
                fail: (err)=>{
                  console.log('打开设置失败',err)
                },
              });
            }
          },
        });
      }
        // 进入页面调用
      const theFirstGet = ()=>{
       uni.getSetting({
        success:async (result)=>{
          if(result.authSetting['scope.userLocation']){
            console.log('已经授权')
            try {
              await getAuthRize()
            } catch (error) {
              getLocalFail();
            }
          }else{
            getCurrentLocation();
          }
        },
       });
      }


      // 直接点击按钮打开设置调用
      const sssss = ()=>{
        uni.getLocation({
          type: 'gcj02',
        });
        uni.openSetting({
          success: (res)=>{
            console.log('打开设置成功2',res)
          },
          fail: (err)=>{
            console.log('打开设置失败2',err)
          },
        })
      }


      const theSecondGet = async ()=>{
         uni.authorize({
            scope: 'scope.userLocation',
          });
      }
      2025-12-17
      回复
登录 后发表内容