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