我的代码:
import ImagePicker from 'react-native-image-picker';
const options = {
title: 'Select Avatar',
customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
const [avatarSource, setAvatar] = useState(null);
myFunc = async () => {
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
setAvatar(source);
}
});
};
return():
<Button title="Image Picker" onPress={myFunc}/>
通过调用myFunc()会发生错误:
未处理的承诺拒绝:TypeError:空值不是对象(正在评估“ ImagePicker.showImagePicker”)
我试图做的事没有帮助:
react-native link react-native-image-picker
并在调用后重建react-native link
"android": {
"permissions": [
"CAMERA",
"WRITE_EXTERNAL_STORAGE"
]
}
和
"ios": {
"infoPlist": {
"NSCameraUsageDescription": "This app uses the camera to scan barcodes on event tickets.",
"NSPhotoLibraryUsageDescription": "This app would like access to your photo gallery",
"NSPhotoLibraryAddUsageDescription": "This app would like to save photos to your photo gallery",
"NSMicrophoneUsageDescription": "This app would like to use your microphone (for videos)"
}
}
有人可以帮忙吗?