查看小程序是否授權(quán) 如沒有授權(quán)則拉起授權(quán)彈框,授權(quán)失敗再次點擊打開設(shè)置頁面
js代碼
Page({
data: {
openSettinged: fasle
},
getCameraAuth(){
let _this = this;
wx.getSetting({ //查看已授權(quán)列表
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>獲取拍照權(quán)限</view>
</button>
<view bindtap="getCamera" wx:else>獲取拍照權(quán)限</view>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。