判断是否开启录音权限是否开启没有开启则提示用户前去开启权限
//这个是写在点击事件里面的
let that = this
uni.authorize({
scope: 'scope.record',//这里选择scope.(录音、位置、用户信息...都可以)
success() { //1.1 允许授权
that.timer = setInterval(that.startTimer, 1000),//录音定时器
recorderManager.start()//开始录音
},
fail() { // 拒绝授权
uni.showModal({
content: '检测到您没打开录音功能权限,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success: (res) => {
if (res.confirm) {
uni.openSetting({//opensetting是调起设置页面的
success: (res) => {
console.log(res.authSetting);
if(res.authSetting == true){//判断res.authsetting的值是true还是false
that.timer = setInterval(that.startTimer,1000),
recorderManager.start()
}else{
console.log("什么也不做");
}
}
})
} else {
console.log('取消');
return false;
}
}
})
return false;
}
})
检查并开启录音权限的实现逻辑
该代码段用于检查用户是否开启录音权限,如果没有开启,则弹出提示并引导用户前往设置页面开启。成功获取权限后,启动录音定时器并开始录音。若用户在模态框中选择确认,会调用uni.openSetting打开设置页面。
3784

被折叠的 条评论
为什么被折叠?



