在用uni-app開發(fā)小程序的時(shí)候我們經(jīng)常會(huì)遇到,需要授權(quán)的時(shí)候,用戶沒有點(diǎn)擊確認(rèn)按鈕,然后用戶再次點(diǎn)擊的時(shí)候,系統(tǒng)默認(rèn)執(zhí)行失敗回調(diào)函數(shù),權(quán)限獲取無法再次被掛起。
1、授權(quán)登錄
先調(diào)取uni.getUserProfile? 設(shè)置desc: 'Wexin'
再調(diào)去uni.login
然后用返回的code碼向接口換取open-id
再用open-id向接口請(qǐng)求userid完成登錄
2、獲取麥克風(fēng)授權(quán)
直接上一個(gè)示例點(diǎn)擊函數(shù)
startRecord() {
?? ??? ??? ??? ?this.ti = '00:00'
?? ??? ??? ??? ?this.minutes = 0
?? ??? ??? ??? ?this.seconds = 0;
?? ??? ??? ??? ?recorderManager.stop();
?? ??? ??? ??? ?// console.log('開始錄音');
?? ??? ??? ??? ?let that = this
?? ??? ??? ??? ?uni.authorize({
?? ??? ??? ??? ??? ?scope: 'scope.record',
?? ??? ??? ??? ??? ?success() { //1.1 允許授權(quán)
?? ??? ??? ??? ??? ??? ?that.opening = false,
?? ??? ??? ??? ??? ??? ??? ?that.closeing = true,
?? ??? ??? ??? ??? ??? ??? ?that.timer = setInterval(that.startTimer, 1000),
?? ??? ??? ??? ??? ??? ?recorderManager.start()
?? ??? ??? ??? ??? ?},
?? ??? ??? ??? ??? ?fail() { //1.2 拒絕授權(quán)
?? ??? ??? ??? ??? ??? ?uni.showModal({
?? ??? ??? ??? ??? ??? ??? ?content: '檢測(cè)到您沒打開錄音功能權(quán)限,是否去設(shè)置打開?',
?? ??? ??? ??? ??? ??? ??? ?confirmText: "確認(rèn)",
?? ??? ??? ??? ??? ??? ??? ?cancelText: '取消',
?? ??? ??? ??? ??? ??? ??? ?success: (res) => {
?? ??? ??? ??? ??? ??? ??? ??? ?if (res.confirm) {
?? ??? ??? ??? ??? ??? ??? ??? ??? ?uni.openSetting({
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?success: (res) => {
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?// console.log(res.authSetting);
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?if (res.authSetting == true) {
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?that.opening = false,
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?that.closeing = true,
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?that.timer = setInterval(that.startTimer,
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?1000),
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?recorderManager.start()
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?// console.log("什么也不做");
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?}文章來源:http://www.zghlxwxcb.cn/news/detail-487257.html
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ??? ??? ??? ??? ?// console.log('取消');
?? ??? ??? ??? ??? ??? ??? ??? ??? ?return false;
?? ??? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ??? ?return false;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?})
?? ??? ??? ?},文章來源地址http://www.zghlxwxcb.cn/news/detail-487257.html
到了這里,關(guān)于uni_app授權(quán)登錄及授權(quán)麥克風(fēng)防止用戶點(diǎn)擊拒絕按鈕,權(quán)限無法再次被掛起。的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!