Reputation: 9
I have tired with this issue
import ImagePicker from 'react-native-image-picker';
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 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 };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source,
});
}
});[enter image description here][1]
Upvotes: 0
Views: 1505
Reputation: 2621
I also was dealing with this weird issue for a couple of days, in some threats in Github and some other questions here I could not find a solution that really solved the problem from my side till I found this bizarre but effective one! Here are the steps I followed:
1.- Open Xcode and from your project directory, go to the folder libraries. After that, go and find RNImagePicker
and open Products folder.
2.- Go to the Build Phases Tab.
3.- Then drag and drop libRnImagePicker.a
to Link Binary With Libraries.
This step is the magic one, by doing this a missed link relation in your project is going to be generated by this time your project should look like this:
4.- Close your project
5.- Run sudo rm -rf node_modules/.cache
6.- After this, compile your project either with Xcode or with react-native run-ios While the compilation happens and the link dependency gets register it will return an error of cycle dependencies (But this is actually good news, we are almost there!)
7.- Open again the route described in step 1 and remove libRNImagePicker.a
by clicking in the minus buttom.
8.- Run your project again, and voila! The react-native-image-picker
is working! :)
Upvotes: 0
Reputation: 1314
When you use react-native-link
it affects 3 files in your android folder, the build.gradle
file (located android/app), the settings.gradle
(located android/) and the MainApplication.java
file (located android/app/src/java).
Normally while linking, the dependencies don't get applied in build.gradle
at times. Therefore check whether the package (react-native-image-picker
) is added, if not go ahead and add it as compile project(':react-native-image-picker')
.
Likewise, check all the other files specified above whether the package is defined.
This is for android (I misunderstood the question as i experienced the same issue and fixed it for android)
Upvotes: 0
Reputation: 2357
You should restart the packager , every time you run link command in order to take effect. Just cancel the running packager and run react-native run-ios
again
Upvotes: 2