swan.authorize
解释: 提前向用户发起授权请求。
方法参数
Object object
object参数说明
scope 有效值列表
示例
在开发者工具中预览效果
扫码体验
请使用百度APP扫码
图片示例
代码示例
-
<view class="container"> <view class="card-area"> <button s-for="item in items" id="{{item.id}}" bind:tap="btnClick" type="primary" hover-stop-propagation="true">{{item.name}}</button> </view></view>
-
Page({data: {title: 'authorize',items: [{name: '授权获取用户信息',id: 'scope.userInfo'}, {name: '授权获取位置信息',id: 'scope.userLocation'}, {name: '授权保存到相册',id: 'scope.writePhotosAlbum'}, {name: '授权获取收货地址',id: 'scope.address'}, {name: '授权获取发票抬头',id: 'scope.invoiceTitle'}, {name: '授权获取录音功能',id: 'scope.record'}, {name: '授权使用摄像头',id: 'scope.camera'}]},btnClick(e) {let scope = e.currentTarget.id;swan.authorize({scope,success: res => {swan.showToast({title: '已成功授权',icon: 'none'});},fail: err => {if (err.errCode === 10003) {swan.showToast({title: '你已拒绝授权申请',icon: 'none'});}}});}});
错误码
授权接口通用错误码
Android
iOS
Bug & Tip
tip:授权操作为异步操作,完成前请不要多次调用。
