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