目前我正在通过终端和 Atom 编辑器运行我的 React Native 项目。我正在尝试使用 https://github.com/marcshilling/react-native-image-picker 中的 rect-native-image-picker并按照说明进行安装:npm install react-native-image-picker@latest --save
我的依赖项
显示:"react-native-image-picker": "^0.22.8"
然后我尝试按照确切的示例进行操作,但当我按下按钮进行选择时,ImagePicker.showImagePicker(options, (response) => {...})
仍然出现错误图像:无法读取未定义的属性“showImagePicker”
所以我 console.log(ImagePicker)
of import ImagePicker from 'react-native-image-picker'
,这正是它在来自 react-native-image-picker 的示例项目,它记录了:
所以我克隆了示例项目以及console.log(ImagePicker)
,它显示:
我开始相信问题是我没有获得我应该获得的功能,例如 launchCamera
和 launchImageLibrary
。我似乎无法弄清楚为什么。我可能遗漏了什么或做错了什么?
最佳答案
您使用的是什么版本的 RN 和 iOS?如果您确定已将 npm 包与 native 代码 (rnpm link
) 链接,您可以尝试添加到您的 Info.plist
(右键->作为源代码打开)<dict>
之间标签:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
关于javascript - 为什么在 React Native 中 react-native-image-picker 的 showImagePicker 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39720545/