我正在使用react-native-permissions
,起初我以为是RN版本问题,所以我将库版本为0.54
从0.52
降级到1.1.1
。我试图将代码放入各种生命周期组件中,例如componmentDidMount()
和componentDidUpdate()
:
_requestPermission = (reqFor) => {
Permissions.request(reqFor).then(response => {
})
}
_AskForPermissions = () => {
Permissions.checkMultiple(['camera', 'photo', 'storage', 'location']).then(response => {
//console.log(response.camera);
if (response.camera != 'authorized') {
this._requestPermission('camera')
}
if (response.photo != 'authorized') {
this._requestPermission('photo')
}
if (response.storage != 'authorized') {
this._requestPermission('storage')
}
if (response.location != 'authorized') {
this._requestPermission('location')
}
})
}
我在manifest
中也设置了权限,但是要注意的是,当我执行react-native link react-native-permissions
时,它仅链接到iOS而不是Android。那可能是问题所在吗?