小程序授权

原创 tigon  2021-08-19 18:25:32  阅读 174 次 评论 0 条
export function isAuthLocation() {
  return new Promise((resolve, reject) => {
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              console.log('这里是点击确认按钮授权成功后操作???');
              wx.getLocation({
                isHighAccuracy: true,
                success(res) {
                  resolve(res)
                },
              });
            },
            fail() {
              console.log('这里是拒绝的操作');
              resolve('1')
            }
          })
        }else {
          console.log('授权过了');
          wx.getLocation({
            isHighAccuracy: true,
            success(res) {
              resolve(res)
            },
            fail() {
              resolve('2')
            }
          });
        }
      }
    })
  })
}
本文地址:https://webge.net/?id=132
版权声明:本文为原创文章,版权归 tigon 所有,欢迎分享本文,转载请保留出处!
NEXT:已经是最新一篇了

评论已关闭!