2

我正在尝试使用 react-native-image-picker,但出现错误:NativeModule.ImagePickermanager 为空。

import React, { Component } from 'react';
import { Text, View, StyleSheet, Alert, PixelRatio, Image } from 'react-native';
import ImagePicker from 'react-native-image-picker';
...
handleChoosePhoto = () => {
    const options = {
      noData: true,
    };
    ImagePicker.launchImageLibrary(options, response => {
      if (response.uri) {
        this.setState({ photo: response });
      }
    });
};

...

<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            {this.state.photo && (
    <Image
       source={{ uri: this.state.photo.uri }}
       style={{ width: 300, height: 300 }}
    />
  )}
  <Button title="Choose Photo" onPress={this.handleChoosePhoto} />
</View>

我试着跑react-native link react-native-image-picker。当我运行这个命令时,什么也没有发生。它在终端中不显示任何内容。我正在使用IOS模拟器。

4

2 回答 2

5

从过去 8 小时开始,我一直在尝试解决此错误,但未能成功。请使用世博会的 I​​magePicker,这是它的链接。https://docs.expo.io/versions/latest/sdk/imagepicker/ 它将解决您的错误。

于 2019-07-29T05:58:27.823 回答
3

我也有同样的问题 。这对我有用。

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

于 2019-10-28T12:41:40.623 回答