苹果手机设置关闭相机权限,为什么小程序授权摄像头以后也不能使用摄像头?
发布于 5 年前 作者 jietan 5697 次浏览 来自 官方Issues

目前的情况是:在手机“设置”>"微信">关闭“相机”和“麦克风”权限后,在小程序中使用wx.authorize进行授权,授权成功后仍然无法使用相机的权限。

我的疑问是:1、上面的现象是苹果手机自身控制的吗?还是我使用的方式有误?2、在手机系统中关闭“相机”和“麦克风”权限后,我在小程序中怎样能调用起摄像头权限?


3 回复

因为你从根本上拒绝了微信app的授权,授权小程序里 应该都是失败。

这就好比 你有一个保险柜在房间里放着, 你给了某个人保险柜钥匙拿东西,但是没有给房间门钥匙。 那人就算是有一万把保险柜钥匙,他也拿不上东西,因为进不去门。 同样的,小程序的api功能都是基于手机系统给微信授权了的, 你现在把微信的权限关了, 小程序当然调不起来。 因为小程序的操作都需要通过微信本身再去调用系统, 微信就相当于小程序和手机系统中间的一座桥, 没有桥了,当然走不通。

授权是这样写的

wx.getSetting({

success(res) {

if (!res.authSetting['scope.camera']) { //获取摄像头权限

wx.authorize({

scope: 'scope.camera',

success() {

console.log('授权成功')

}, fail() {

console.log('授权fail')

wx.showModal({

title: '提示',

content: '尚未进行授权,部分功能将无法使用',

showCancel: false,

success(res) {

if (res.confirm) {

console.log('用户点击确定')

wx.openSetting({ //这里的方法是调到一个添加权限的页面,可以自己尝试

success: (res) => {

if (!res.authSetting['scope.camera']) {

wx.authorize({

scope: 'scope.camera',

success() {

console.log('授权成功')

}, fail() {

console.log('用户点击取消')

}

})

}

},

fail: function () {

console.log("授权设置录音失败");

}

})


} else if (res.cancel) {

console.log('用户点击取消')

}

}

})

}

})

};

if (!res.authSetting['scope.record']) { //获取录音权限

console.log("333333333333333333333333333333333333333333333333333");

wx.authorize({

scope: 'scope.record',

success() {

console.log('授权成功')

}, fail() {

wx.showModal({

title: '提示',

content: '尚未进行授权,部分功能将无法使用',

showCancel: false,

success(res) {

if (res.confirm) {

wx.openSetting({

success: (res) => {

if (!res.authSetting['scope.record']) {

wx.authorize({

scope: 'scope.record',

success() {

console.log('授权成功')

}, fail() {

console.log('用户点击取消')

}

})

}

},

fail: function () {

console.log("授权设置录音失败");

}

})

} else if (res.cancel) {

console.log('用户点击取消')

}

}

})

}

})

}

},

fail(res) {

console.log("22222222222222222"+JSON.stringify(res));

}

})

回到顶部