小程序 权限设置
(1)獲取用戶的授權(quán)信息wx.getSetting({withSubscriptions: true, 是否同時(shí)獲取用戶訂閱消息的訂閱狀態(tài),默認(rèn)不獲取,注意:withSubscriptions只返回用戶勾選過訂閱面板中的“總是保持以上選擇,不再詢問”的訂閱消息。success: function (res) { 會(huì)返回已經(jīng)授權(quán)的信息}})(2)打開微信后臺(tái)授權(quán)信息控制臺(tái):wx.openSetting({withSubscriptions: true, 是否同時(shí)獲取用戶訂閱消息的訂閱狀態(tài),默認(rèn)不獲取,注意:withSubscriptions只返回用戶勾選過訂閱面板中的“總是保持以上選擇,不再詢問”的訂閱消息。success: function (res) {console.log(res.authSetting) 當(dāng)成功返回后,會(huì)返回控制臺(tái)中授權(quán)的布爾信息}})(3)彈出窗口進(jìn)行授權(quán)操作wx.authorize({scope: 'scope.record',success: function () {成功授權(quán)后操作}})多在(1)進(jìn)行判斷是否授權(quán)后,再進(jìn)行彈框操作如:可以通過wx.getSetting先查詢一下用戶是否授權(quán)了"scope.record"這個(gè)scopewx.getSetting({success(res) {if (!res.authSetting['scope.record']) {wx.authorize({scope: 'scope.record',success () {用戶已經(jīng)同意小程序使用錄音功能,后續(xù)調(diào)用wx.startRecord接口不會(huì)彈窗詢問wx.startRecord()}})}}})(3.5)通過app.json配置權(quán)限{"pages": ["pages/index/index"],"permission": {"scope.userLocation": {"desc": "你的位置信息將用于小程序位置接口的效果展示" 高速公路行駛持續(xù)后臺(tái)定位}}}(4)用戶點(diǎn)擊拒絕授權(quán)后,再次點(diǎn)擊不再?gòu)棾龃翱?引導(dǎo)用戶再次授權(quán)調(diào)用wx.openSetting讓用戶自主授權(quán)授權(quán)信息參數(shù):scope.address 是否授權(quán)通訊地址,對(duì)應(yīng)接口 wx.chooseAddressscope.camera 是否授權(quán)攝像頭,對(duì)應(yīng)[camera](https://developers.weixin.qq.com/miniprogram/dev/component/camera.html) 組件scope.invoice 是否授權(quán)獲取發(fā)票,對(duì)應(yīng)接口 wx.chooseInvoicescope.invoiceTitle 是否授權(quán)發(fā)票抬頭,對(duì)應(yīng)接口 wx.chooseInvoiceTitlescope.record 是否授權(quán)錄音功能,對(duì)應(yīng)接口 wx.startRecordscope.userInfo 是否授權(quán)用戶信息,對(duì)應(yīng)接口 wx.getUserInfo,如今不會(huì)彈出授權(quán)窗口,請(qǐng)使用用戶信息新接口(如:wx.getUserProfile)scope.userLocation 是否授權(quán)地理位置,對(duì)應(yīng)接口 wx.getLocation, wx.chooseLocationscope.userLocationBackground 后臺(tái)定位,對(duì)應(yīng)接口wx.startLocationUpdateBackground scope.werun 是否授權(quán)微信運(yùn)動(dòng)步數(shù),對(duì)應(yīng)接口 wx.getWeRunDatascope.writePhotosAlbum 是否授權(quán)保存到相冊(cè) wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum(5)打開手機(jī)系統(tǒng)給微信的授權(quán)界面wx.openAppAuthorizeSetting({success,...})(6)獲取手機(jī)系統(tǒng)給微信的授權(quán)信息const appAuthorizeSetting = wx.getAppAuthorizeSetting()albumAuthorized 允許微信使用相冊(cè)的開關(guān)(僅iOS有效)bluetoothAuthorized 允許微信使用藍(lán)牙的開關(guān)(僅iOS有效)cameraAuthorized 允許微信使用攝像頭的開關(guān)locationAuthorized 允許微信使用定位的開關(guān)locationReducedAccuracy 定位準(zhǔn)確度。true表示模糊定位,false表示精確定位(僅iOS有效)microphoneAuthorized 允許微信使用麥克風(fēng)的開關(guān)notificationAuthorized 允許微信通知的開關(guān)notificationAlertAuthorized 允許微信通知帶有提醒的開關(guān)(僅iOS有效)notificationBadgeAuthorized 允許微信通知帶有標(biāo)記的開關(guān)(僅iOS有效)notificationSoundAuthorized 允許微信通知帶有聲音的開關(guān)(僅iOS有效)phoneCalendarAuthorized 允許微信讀寫日歷的開關(guān)
總結(jié)
- 上一篇: windows运行命令大全
- 下一篇: 一支笔的测试点_一支笔的测试