查看小程序是否授权 如没有授权则拉起授权弹框,授权失败再次点击打开设置页面
js代码
Page({
data: {
openSettinged: fasle
},
getCameraAuth(){
let _this = this;
wx.getSetting({ //查看已授权列表
success(res){
console.log(res)
if(!res.authSetting['scope.camera']){
wx.authorize({
scope: 'scope.camera',
success(){
_this.setData({openSettinged: false})
console.log('success')
},fail(){
console.log('fail')
_this.setData({openSettinged:true})
}
})
}
},
})
},
})
html代码
<button wx:if="{{openSettinged}}" class="city-now" catchopensetting="getCamera" open-type="openSetting">
<view>获取拍照权限</view>
</button>
<view bindtap="getCamera" wx:else>获取拍照权限</view>
网友评论