Currently I am running my React Native project via terminal and Atom editor. I am trying to use rect-native-image-picker from https://github.com/marcshilling/react-native-image-picker and followed the instructions to install: npm install react-native-image-picker@latest --save
And my dependencies
show: "react-native-image-picker": "^0.22.8"
Then I tried following the exact example, yet I am still getting an error on ImagePicker.showImagePicker(options, (response) => {...})
when I press the button to choose an image: Cannot read property 'showImagePicker' of undefined
So I console.log(ImagePicker)
of import ImagePicker from 'react-native-image-picker'
, which is exactly how it is implemented in the Example project from react-native-image-picker, and it logged:
So I cloned the Example project and also console.log(ImagePicker)
and it showed:
I am starting to believe that the issue is that I am not getting functions that I am supposed to get, such as launchCamera
and launchImageLibrary
. I can't seem to figure out why. What could I be missing or doing incorrectly?
What version of RN and iOS do you use? If you are sure that you linked npm package with native code ( rnpm link
), you can try add to your Info.plist
(right key -> Open as source code) between <dict>
tags:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
I have also faced the same issue. So in the documentation, the auto-linking is given but it is not linking all the dependency. You need to link some dependency manually. Please follow this below link it will help you. For manually linking follow this
I'm not an expert but you can solved this issue thanks to :
I'm not an expert but you can solved this issue thanks to :
Don't hesitate to remove your nodes_modules and pod files then restart your server
Don't hesitate to remove your nodes_modules and pod files then restart your server
Do this:
import {launchCamera, launchImageLibrary} from 'react-native-image-picker'; launchCamera(options, response => { if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { alert('ImagePicker Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { alert(response.uri) } });
The reason is that ImagePicker.showImagePicker is depreciated
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.