我希望用户使用相机或照片库选择个人资料图片。我使用 react-native-image-picker 给用户选择.....使用下面的代码:
import ImagePicker from 'react-native-image-picker';
export const _imagePickHandler = userId => {
const options = {
title: 'Select Profile Pic',
takePhotoButtonTitle: 'Take photo with your camera',
chooseFromLibraryButtonTitle: 'Choose photo from library',
};
ImagePicker.showImagePicker(options, async imgPickResponse => {
if (imgPickResponse.didCancel) {
console.log('User cancelled image picker');
} else if (imgPickResponse.error) {
console.log('Image Picker Error: ', imgPickResponse.error);
} else {
//code for success
}
});
};
当用户单击“拒绝”时,imgPickResponse.error
返回Permissions weren't granted
......这是预期的。
但是,当用户单击“拒绝并且不再询问”时,问题就来了...... imgPickResponse.error
AGAIN 返回Permissions weren't granted
。但是,如果用户选择了这个,我想要一个不同的行动方案。
另外...如果我使用回调函数中的check()
方法,我会遇到同样的问题;无论用户是“拒绝”还是“拒绝并且不再询问”,我都会得到相同的“拒绝”回复......它不会像我所期望的那样给我“阻止”。请参阅下面的代码react-native-permissions
showImagePicker()
export const _checkPermissions = async permission => {
let result = await check(
Platform.select({
android: PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,
ios: PERMISSIONS.IOS.PHOTO_LIBRARY,
}),
);
return result;
};
我正在使用 react-native-permissons 版本 2.1.5
最后,这是我的 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>