亲测有用 3.X 使用showImagePicker会报错 2.3.0也会报错
使用的react-native-image-picker@2.3.4 可以使用showImagePicker方法
yarn add react-native-image-picker@2.3.4
#RN >= 0.60(如果你的react-native版本 > = 0.60执行以下命令)
npx pod-install
#RN < 0.60(如果你的react-native版本< 0.60执行以下命令)
react-native link react-native-image-picker@2.3.4
js中使用
import ImagePicker from 'react-native-image-picker';
const options = {
title: '请选择',
cancelButtonTitle:'取消',
takePhotoButtonTitle:'拍照',
chooseFromLibraryButtonTitle:'从相册选择',
storageOptions: {
skipBackup: true,
path: 'images',
},
};
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) {
Alert.alert('自定义按钮:' + response.customButton)
} else {
const source = { uri: response.uri };
Alert.alert(JSON.stringify(source))
console.log("source:" + JSON.stringify(source))
}
});
Android:
IOS: