设置API:wx.openSetting,wx.getSetting使用说明(示例:地图授权与取消授权后的重新授权)
这个API解决了过去一个长久以来无法解决的问题,如何让用户重复授权;
打开小程序的设置界面:就是主动调取授权
官方文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/setting.html#opensettingobject
基础库版本 1.1.0 开始支持,低版本需做兼容处理调起客户端小程序设置界面,返回用户设置的操作结果
| scope | 对应接口 |
| scope.userInfo | wx.getUserInfo |
| scope.userLocation | wx.getLocation, wx.chooseLocation |
| scope.address | wx.chooseAddress |
| scope.record | wx.startRecord |
相关文章:微信小程序重新调起授权用户信息,扫码进入小程序获取二维码携带参数wx.openSetting,wx.setClipboardData,wx.getClipboardData
微信小程序最新更新--api测试一览
微信小程序之新版本测试
相关讨论:
wx.openSetting()怎么判断success里面 用户有没有授权了我写的
|
1
2
3
4
5
6
7
8
9
|
wx.openSetting({ success:(res)=>{ console.log("授权结果..") console.log(res) if(!res.authSetting.scope.userInfo || !res.authSetting.scope.userLocation){ applyNotice() } } }) |
[AppleScript] 纯文本查看 复制代码
123456789wx.openSetting({success:(res)=>{console.log("授权结果..")console.log(res)if(!res.authSetting["scope.userInfo"] || !res.authSetting["scope.userLocation"]){applyNotice()}}})试试上述改动。
相关讨论:
用户取消后如何再次调出允许授权的modal?
如果用户错点了拒绝,就没办法再继续进入使用小程序了。能重新再调出许可的小窗让用户重新再选择吗?
答:林超
使用 wx.openSetting接口
用户如果不小心拒绝了授权,之前是过十分钟之后还可以被唤醒,最近发现唤不醒了,一直是:"getUserInfo:fail auth deny",该如何应对?
答:Tïedào
//如下,在getUserInfo失败后调用wx.openSetting即可
如下是我的真实示例:
// pages/contactus/contactus.js
var app = getApp()
Page({ /**
* 页面的初始数据
*/
data: {
loadingHidden: false,
latitude: 23.099994,
longitude: 113.324520,
markers: [{
iconPath: '../../images/location.png',
id: 1,
latitude: 31.245442,
longitude: 121.506337,
title: '千卉摄影',
width: 50,
height: 50,
callout: {
content: '千卉摄影',
color: '#ff00000',
fontSize: '18',
borderRadius: '5',
bgColor: '#ffffff',
padding: '10',
display: 'ALWAYS',
textAlign: 'center'
}
}],
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
wx.getSystemInfo({
success: function (res) {
// console.log(res)
that.setData({
scrollHeight: res.windowHeight
});
}
});
wx.getSetting({
success(res) {
console.log(!res.authSetting['scope.userLocation']);
if (!res.authSetting['scope.userLocation']) {
wx.authorize({
scope: 'scope.userLocation',
success() {
// 用户已经同意
//其他操作...
console.log("用户已经同意位置授权");
},
fail() {
console.log("用户已经拒绝位置授权");
that.openConfirm();//如果拒绝,在这里进行再次获取授权的操作
}
})
}
//其他操作..
}
});
},
//当用户第一次拒绝后再次请求授权
openConfirm: function () {
wx.showModal({
content: '检测到您没打开此小程序的定位权限,是否去设置打开?',
confirmText: "确认",
cancelText: "取消",
success: function (res) {
console.log(res);
//点击“确认”时打开设置页面
if (res.confirm) {
console.log('用户点击确认')
wx.openSetting({
success: (res) => { }
})
} else {
console.log('用户点击取消')
}
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function (e) {
this.mapCtx = wx.createMapContext('myMap')
}, /**
* 生命周期函数--监听页面显示
*/
onShow: function () {
var that = this
app.reqGetfunc.reqGet('qh_contact.html', {}, function (res) {
// console.log(res)
that.setData({
tel: res.tel,
address: res.address,
map: res.map,
qq: res.qq,
wechat: res.wechat,
code: res.code,
loadingHidden: true
}) })
},
getLocation:function(){
var that = this
wx.getSetting({
success(res) {
console.log(res)
if (!res.authSetting['scope.userLocation']) {
wx.authorize({
scope: 'scope.userLocation',
success() {
// 用户已经同意小程序使用此功能,后续调用 wx.getLocation 接口不会弹窗询问
wx.getLocation({
type: 'gcj02',
success: function (res) {
//console.log(res)
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
console.log("latitude:" + latitude)
console.log("longitude:" + longitude)
console.log("speed:" + speed)
console.log("accuracy:" + accuracy)
wx.openLocation({
name: '山东省',
address: '山东省临沂市千卉摄影',
//latitude: latitude,
//longitude: longitude,
latitude: Number(that.data.map.latitude),
longitude: Number(that.data.map.longitude),
scale: 28
})
}
})
},
fail() {
console.log("用户已经拒绝位置授权");
that.openConfirm();//如果拒绝,在这里进行再次获取授权的操作
}
})
}
}
})
},
chooseLocation:function(){
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
wx.authorize({
scope: 'scope.userLocation',
success(){
wx.chooseLocation({
success: function (res) {
var name = res.name
var address = res.address
var latitude = res.latitude
var longitude = res.longitude
}
})
} })
}
},
fail() {
console.log("用户已经拒绝位置授权");
that.openConfirm();//如果拒绝,在这里进行再次获取授权的操作
}
}) },
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})
设置API:wx.openSetting,wx.getSetting使用说明(示例:地图授权与取消授权后的重新授权)的更多相关文章
- 小程序获取地址授权的修改 wx.openSetting需点击
开发者可以通过 wx.openSetting 接口来打开小程序设置界面并返回用户的设置结果.在原来的 wx.openSetting 接口中,我们允许开发者直接调用此接口,但目前我们发现有不少开发者滥用 ...
- [转]微信小程序联盟 跳坑《一百八十一》设置API:wx.openSetting使用说明
本文转自:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=4066 这个API解决了过去一个长久以来无法解决的问题,如何让用户重 ...
- 微信小程序(mpvue) wx.openSetting 无法调起设置页面
在开发过程有个需要保存图片/视频到设备相册的业务,so easy~ 巴啦啦撸下来了完整功能, wx.saveVideoToPhotosAlbum 会自动调起用户授权,美滋滋~~ btu.... ...
- 微信小程序-用户拒绝授权使用 wx.openSetting({}) 重新调起授权用户信息
场景模拟:用户进入微信小程序-程序调出授权 选择拒绝之后,需要用到用户授权才能正常使用的页面,就无法正常使用了. 解决方法:在用户选择拒绝之后,弹窗提示用户 拒绝授权之后无法使用,让用户重新授权(微信 ...
- 微信小程序API交互反馈,wx.showToast显示消息提示框
导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...
- 微信授权 - wx.openSetting
wx.openSetting({ // 唤醒授权页面 success: res => { console.log('res',res) // 授权成功操作 }, ...
- 微信JS-SDK“分享信息设置”API及数字签名生成方法(NodeJS版本)
原文:微信JS-SDK"分享信息设置"API及数字签名生成方法(NodeJS版本) 先上测试地址以示成功: 用微信打开下面地址测试 http://game.4gshu.com/de ...
- 小程序中navigator和wx.navigateTo,wx.redirectTo,wx.reLaunch,wx.switchTab,wx.navigateBack的用法
如果用一句话来表明navigator和API中wx.系列的跳转有什么区别,那就是navigator是在wxml中用标签添加open-type属性来达到和wx.系列一样的效果. navigator的属性 ...
- 微信 小程序 drawImage wx.canvasToTempFilePath wx.saveFile 获取设备宽高 尺寸问题
以下问题测试环境为微信开发者0.10.102800,手机端iphone6,如有不对敬谢指出. 根据我的测试,context.drawImage,在开发者工具中并不能画出来,只有预览到手机中显示. wx ...
随机推荐
- Django的Form验证
Django的Form验证 Form验证:Form提交Form表单数据验证 针对Form提交的数据进行验证 创建模板 class loginForm() 请求提交给模板,创建对象 obj=loginF ...
- Cookie与Session会话技术
Cookie与Session会话技术 一.什么是会话 会话:当用户打开浏览器,访问多个WEB资源,然后关闭浏览器的过程,称之为一个会话,选项卡,弹出页面都属于这个会话,且共享同一个session. 二 ...
- js中数组去重方法及性能对比
js中数组的 数组去重 常用的数组去重方法以及效率分析: 首先我们先构建一个数组,主要是用于进行去重实验,我们主要实验的量级为1000,10000,100000,500000.具体的生成数组的方法如下 ...
- Spring Boot 为什么这么火?
没错 Spring Boot 越来越火了,而且火的超过了我的预期,作为一名行走一线的 Java 程序员,你可能在各个方面感受到了 Spring Boot 的火. Spring Boot 的火 技术社区 ...
- winform删除dataGridView列报异常:System.IndexOutOfRangeException:“索引 7 没有值
winform界面如下: using System; using System.Collections.Generic; using System.ComponentModel; using Syst ...
- 大部分人都会忽略的Python易错点总结
python中复数实现(-2) 0.5和开根号sqrt(-2)的区别** (-2)**0.5和sqrt(-2)是不同的,前者是复数后者是会报错的. print((-2)**0.5) #输出:(8.65 ...
- 十一、Powell算法(鲍威尔算法)原理以及实现
一.介绍 Powell算法是图像配准里面的常用的加速算法,可以加快搜索速度,而且对于低维函数的效果很好,所以本篇博客主要是为了介绍Powell算法的原理以及实现. 由于网上已经有了对于Powell算法 ...
- 将Excel表结构导入到Powerdesigner
我们经常会在excel中设计整理表结构,整理完需要导入到Powerdesigner中,可以通过以下脚本来实现快速,具体操作方法: 打开PowerDesigner,新建模型,点击Tools|Execut ...
- 《移动WEB前端高级开发实践@www.java1234.com》——3
React Flux: Flux将一个应用分成四个部分. View: 视图层 Action(动作):视图层发出的消息(比如mouseClick) Dispatcher(派发器):用来接收Actions ...
- vue 路由对象
路由对象在使用了 vue-router 的应用中,路由对象会被注入每个组件中,赋值为 this.$route ,并且当路由切换时,路由对象会被更新. so , 路由对象暴露了以下属性: 1.$rout ...
