swan.openSetting
解释: 调起客户端智能小程序设置界面,返回用户设置的操作结果。swan.openSetting 可打开的控制面板权限详见需授权接口列表。Web 态说明 Web 态暂不支持用户主动切换授权开关,接口调用会进入失败回调(fail)。
方法参数
Object object
object参数说明
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|
success | Function | 否 | | 接口调用成功的回调函数 |
fail | Function | 否 | | 接口调用失败的回调函数 |
complete | Function | 否 | | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数说明
参数 | 类型 | 说明 |
---|
authSetting | Object | 用户授权结果,其中 key 为 scope 值,value 为 Bool 值,表示用户是否允许授权。 |
错误码
Android
错误码(errCode) | 说明 |
---|
201 | 解析失败,请检查调起协议是否合法 |
1001 | 执行失败 |
iOS
错误码(errCode) | 说明 |
---|
202 | 解析失败,请检查参数是否正确 |
Web 态
错误信息(errMsg) | 类型 | 说明 |
---|
API swan.openSetting is not supported in web | string | 不支持 |
示例
扫码体验
请使用百度APP扫码
图片示例
代码示例1 - API打开授权设置页 :
在开发者工具中预览效果
<view class="container">
<view class="page-body">
<button bind:tap="openSetting" type="primary" hover-stop-propagation="true">打开设置</button>
</view>
<view class="page-title">
<view class="page-title-line"></view>
<view class="page-title-text">{{title}}</view>
</view>
</view>
Page({
data: {
title: 'openSetting'
},
openSetting() {
swan.openSetting({
success: res => {
// 正常的业务逻辑
},
fail: res => {
// 异常处理逻辑
}
});
}
});
代码示例2 - button组件打开授权设置页 :
在开发者工具中预览效果
<view class="container">
<view class="page-body">
<button bindopensetting="openSetting" type="primary" open-type="openSetting">打开设置</button>
</view>
</view>
Page({
openSetting(){
swan.showToast({
title: '打开回调',
icon: 'none'
});
}
});