小程序用户拒绝授权之后,如何下次进来再次弹出授权

在获取授权之前应先获取授权设置 wx.getSetting ,
获取结果 res.authSetting[‘scope.userInfo’],结果为 false,则可以引导用户允许微信获得你的公共信息,用 wx.openSetting() 调起客户端小程序设置界面,用户允许后将获得用户的公共信息 userInfo

在这里插入图片描述

const app = getApp()
Page({

/**

  • 页面的初始数据
    */
    data: {
    imgList: [], // 上传列表
    src: “”, // 上传视频
    },
    onLoad() {
    this.gethref()
    wx.getSetting({
    success(res) {
    console.log(res)
    if (res.authSetting == true) {
    console.log(‘已授权’)
    } else if (res.authSetting[‘scope.userLocation’] == false) {
    console.log(‘wei授权’)
    wx.openSetting({
    success(res) {
    console.log(res.authSetting)
    console.log(‘wei授权’)
    }
    })
    }

    }
    })
    },
    gethref() {
    wx.getLocation({
    type: ‘wgs84’,
    success(res) {
    const latitude = res.latitude
    const longitude = res.longitude
    const speed = res.speed
    const accuracy = res.accuracy
    console.log(res, ‘res’)
    }
    })

}
})

Guess you like

Origin blog.csdn.net/qq_43671996/article/details/108663698