React Native Image Picker无法读取属性" showImagePicker"未定义的

时间:2018-02-13 23:25:42

标签: javascript ios reactjs react-native

我已按照包react-native-image-picker的所有iOS安装说明进行操作,但在我尝试使用showImagePicker()方法时仍然出现错误。

它告诉我cannot read property "showImagePicker" of undefined

我在我的文件var ImagePicker = require('react-native-image-picker');顶部导入了包,我已多次react-native link,我已将RNImagePicker.xcodeproj添加到我的库文件夹中,我添加了{{1}转到"将二进制文件链接到库",我已将权限添加到我的RNImagePicker.a文件中。

我已经完成了文档中的所有操作,但仍然无效。

这是我的JS:

info.plist

我遇到的唯一问题是,当我尝试在Xcode中构建我的应用时,它失败并显示错误import React from 'react'; import PropTypes from 'prop-types'; import { StyleSheet, Text, View, Image, ScrollView, TextInput, TouchableOpacity, KeyboardAvoidingView } from 'react-native'; var ImagePicker = require('react-native-image-picker'); export default class ProfilePicUploaderPage extends React.Component { state = { ProfilePicLocalSource: null, ProfilePicRemoteSource: null } ChoosePhoto(){ console.log(SOCButton); var options = { title: 'Select Avatar', customButtons: [ {name: 'fb', title: 'Choose Photo from Facebook'}, ], 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) { console.log('User tapped custom button: ', response.customButton); } else { let source = { uri: response.uri }; this.setState({ avatarSource: source }); } }); } render(){ return(<all of my JSX>); }

有没有人知道发生了什么?

1 个答案:

答案 0 :(得分:0)

看起来您没有将ImagePicker导入JS文件。尝试使用import ImagePicker from 'react-native-image-picker'

如果您已正确遵循iOS的链接步骤,那么您应该很好。