单击引导授权的按钮,出现了意想不到的界面
发布于 4 年前 作者 wfeng 1610 次浏览 来自 官方Issues

本来是可以引导用户去设置权限的,结果我却异想天开,设置按钮的open-type=‘openSetting getUserInfo’,想试一下点击按钮时能不能让用户同时设置两种权限,结果出现了如下的界面,看不到权限设置了,最主要的是改回原来的样子后、重启IDE、重启电脑、升级小程序版本后仍然不行,急急急哈~

wxml文件:

<view class="kuang" wx:if='{{!userLocation}}'>
  <text>小程序需要获取你的位置信息,请授权</text>
  <button type="primary" open-type='openSetting' bindopensetting='authorize'>授权设置</button>
</view>

js文件

// miniprogram/pages/yltx/authorize.js
Page({
  authorize(e){
    console.log('authorize',e)
    if(e.detail.authSetting['scope.userLocation']){
      console.log('授权成功')
    }else{
      console.log('没有授权')
    }
  },
  onLoadfunction (options{
    wx.getSetting({
      successres => {
        console.log(111,res)
        let auth=res.authSetting['scope.userLocation']||false
        if(auth){
          wx.redirectTo({
            url'shangbao',
          })
        }else{
          this.setData({userLocation:auth})
        }
      }
    })
  },
})
2 回复

还没有授权,打开设置授权,怎么可能会有,想多了

app.json有权限设置:

  "permission": {
    "scope.userLocation": {
      "desc""上报健康信息时将自动获取你的位置"
    }
  },

清除IDE的缓存等操作后,都不能去设置权限了,急哈
回到顶部