uniapp中 uni.makephonecall拒绝系统权限后如何检查是否被拒绝
在uniapp中,使用uni.makePhoneCall拨打手机号时,如果用户拒绝了系统权限,应该如何检测权限是否被拒绝?有没有办法在调用失败后获取具体的拒绝状态?
2 回复
在uni.makephonecall调用失败后,可以通过uni.authorize或uni.getSetting检查权限状态。若用户拒绝,可引导用户手动开启权限。
示例:
uni.getSetting({
success(res) {
if (!res.authSetting['scope.phone']) {
// 权限被拒绝
}
}
});
在uni-app中,当调用uni.makePhoneCall拨打电话时,如果用户拒绝了系统权限,可以通过以下方式检查权限状态:
核心方法:使用uni.authorize或uni.getSetting检查权限
// 方法1:直接检查权限状态
uni.getSetting({
success(res) {
if (!res.authSetting['scope.record']) {
// 权限被拒绝
console.log('电话权限已被拒绝')
// 这里可以引导用户去设置页开启权限
uni.showModal({
title: '权限提示',
content: '您拒绝了电话权限,无法拨打电话,是否去设置开启?',
success: function (res) {
if (res.confirm) {
uni.openSetting() // 打开设置页面
}
}
})
} else {
// 有权限,执行拨打电话
uni.makePhoneCall({
phoneNumber: '13800138000'
})
}
}
})
// 方法2:先尝试授权,捕获失败情况
uni.authorize({
scope: 'scope.record',
success() {
// 授权成功,拨打电话
uni.makePhoneCall({
phoneNumber: '13800138000'
})
},
fail(err) {
// 授权失败(包括用户拒绝)
console.log('授权失败:', err)
if (err.errMsg.includes('auth deny')) {
// 用户明确拒绝
uni.showModal({
title: '权限提示',
content: '拨打电话需要电话权限,请授权后使用',
success: function (res) {
if (res.confirm) {
uni.openSetting()
}
}
})
}
}
})
关键点说明:
scope.record是电话权限对应的scope- 用户拒绝后,短期内再次调用
authorize不会弹窗,需要引导用户手动开启 - 可以通过
uni.openSetting()引导用户到设置页面开启权限
最佳实践建议:
在调用makePhoneCall前先检查权限状态,被拒绝时给出友好提示并引导用户开启权限。

