Reputation: 2381
I'm trying to use the package react-native-image-picker with IOS emulator.
...
import ImagePicker from 'react-native-image-picker';
...
constructor(props) {
super(props);
this.state = {
avatarSource: null,
};
this.selectPhotoTapped = this.selectPhotoTapped.bind(this);
}
selectPhotoTapped() {
const options = {
quality: 1.0,
maxWidth: 500,
maxHeight: 500,
storageOptions: {
skipBackup: true,
},
};
ImagePicker.showImagePicker(options, response => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
let source = {uri: response.uri};
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source,
});
}
});
}
render() {
...
<TouchableOpacity onPress={this.selectPhotoTapped.bind(this)}>
<View
style={[styles.avatar, styles.avatarContainer, {marginBottom: 20}]}>
{this.state.avatarSource === null ? (
<Text>Select a Photo</Text>
) : (
<Image style={styles.avatar} source={this.state.avatarSource} />
)}
</View>
</TouchableOpacity>
}
When I run the code, I get the error:
I already try to run react-native link react-native-image-picker, but it did not fix the problem. Do I need to link another library?
Thanks
Upvotes: 3
Views: 1082
Reputation: 862
Perform this steps: document:link
Compile and have fun.
OR
try to
Downgrade version
Upvotes: 1
Reputation: 46
These steps worked for me, using the current version 1.0.2 of react-native-image-picker and iOS Simulator 10.3 running iPhone X - 12.4:
npm install
react-native link react-native-image-picker
cd ios && pod install
cd ../ && react-native run-ios
Upvotes: 0