在调用方法onpress时返回错误“ null不是对象(评估'imagepickermanager.showimagepicker')”的错误

时间:2019-04-05 05:18:13

标签: react-native react-native-image-picker

当我尝试使用react-native-image-picker访问照片时,它返回错误“ null不是对象(评估'ImagePickerManager.showImagePicker')”。

我尝试链接删除节点模块的库,然后再次链接等,但是没有任何作用。

const ImagePicker = require("react-native-image-picker");

<TouchableOpacity
                    onPress={() => {
                        const options = {
                            title: "Select Profile Pic",
                            mediaType: "photo",
                            takePhotoButtonTitle: "Take a Photo",
                            maxWidth: 256,
                            maxHeight: 256,
                            allowsEditing: true,
                            noData: true
                        }
                    ImagePicker.showImagePicker(options, response => {
                        if (response.uri){
                            this.setState({photo: response})
                        }

                        })


firebase.storage.ref().child(`chatImg/${this.state.photo.uri}`);
                    }}
                    style={{ flexDirection: 'row' }}
                >
                    <View style={{ width: 15 }} />
                    <AutoHeightImage width={35} source= 
{require('../../resource/icon_attach.png')} />                    
                    <View style={{ width: 5 }} />
                </TouchableOpacity>

3 个答案:

答案 0 :(得分:0)

手动将RNImagePicker.xcodeproj添加到xcode中解决了我的问题。

答案 1 :(得分:0)

我认为当前版本存在错误。我已经经历过了,我要做的是卸载图像选择器软件包上的当前版本,并安装了版本@1.1.0

npm uninstall react-native-image-picker

npm install react-native-image-picker@1.1.0 --save

react-native link react-native-image-picker

cd ios

pod install

cd ..

停止打包程序或捆绑程序,然后重新运行

  

npm start --rest-cache

答案 2 :(得分:0)

卸载最新版本 npm 卸载 react-native-image-picker 已安装版本 0.28.0 npm install react-native-image-picker@0.28.0 --save react-native link react-native-image-picker