/**
* @description: check微信小程序相机权限
* @param {string} toUrl 授权后跳转的页面
*/
export function checkWXAuth(toUrl: string) {
uni.getSetting({
success(res) {
if (!res.authSetting['scope.camera']) {
uni.authorize({
scope: 'scope.camera',
success(res) {
// 授权成功
uni.showToast({
title: '授权成功',
icon: 'none',
success: function () {
uni.redirectTo({
url: toUrl
})
}
})
},
fail() {
uni.showModal({
content: '检测到您没打开获取相机功能权限,是否去设置打开?',
confirmText: '确认',
cancelText: '取消',
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
uni.showToast({
title: '授权后请重新打开此页面',
icon: 'none',
success: function () {
uni.redirectTo({
url: toUrl
})
}
})
},
fail: (err) => {
console.log(err)
}
})
} else {
uni.showToast({
title: '获取授权相机授权失败',
icon: 'none'
// success: function () {
// uni.navigateBack()
// }
})
}
}
})
}
})
} else {
console.log('用户相机权限正常')
}
},
fail() {
uni.showToast({
title: '获取授权相机授权失败',
icon: 'none'
// success: function () {
// uni.navigateBack()
// }
})
}
})
}
版权归属:
Ivy Forest
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区