【问题标题】:IOS React Native ImagePickerManager is nullIOS React Native ImagePickerManager 为空
【发布时间】:2019-07-15 18:59:22
【问题描述】:

我正在尝试将包 react-native-image-picker 与 IOS 模拟器一起使用。

...
import ImagePicker from 'react-native-image-picker';
...

constructor(props) {
    super(props);
    this.state = {
      avatarSource: null,
    };

    this.selectPhotoTapped = this.selectPhotoTapped.bind(this);
}

selectPhotoTapped() {
    const options = {
      quality: 1.0,
      maxWidth: 500,
      maxHeight: 500,
      storageOptions: {
        skipBackup: true,
      },
    };

    ImagePicker.showImagePicker(options, response => {
      console.log('Response = ', response);

      if (response.didCancel) {
        console.log('User cancelled photo 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};

        // You can also display the image using data:
        // let source = { uri: 'data:image/jpeg;base64,' + response.data };

        this.setState({
          avatarSource: source,
        });
      }
    });
  }

  render() {
      ...
      <TouchableOpacity onPress={this.selectPhotoTapped.bind(this)}>
            <View
              style={[styles.avatar, styles.avatarContainer, {marginBottom: 20}]}>
              {this.state.avatarSource === null ? (
                <Text>Select a Photo</Text>
              ) : (
                <Image style={styles.avatar} source={this.state.avatarSource} />
              )} 
            </View>
          </TouchableOpacity>
  }

当我运行代码时,我得到了错误: 我已经尝试运行 react-native link react-native-image-picker,但它并没有解决问题。我需要链接另一个库吗?

谢谢

【问题讨论】:

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


    【解决方案1】:

    执行以下步骤: document:link

    1. 在 XCode 的“项目导航器”中,右键单击您项目的 库文件夹 ➜ 将文件添加到 <...>.
    2. 转到 node_modules ➜ react-native-image-picker ➜ ios ➜ 选择 RNImagePicker.xcodeproj。
    3. 将 libRNImagePicker.a 添加到构建阶段 -> 链接二进制文件 图书馆。
    4. 请参阅安装后步骤。

    编译并玩得开心。

    尝试
    降级版本

    1. npm 卸载 react-native-image-picker
    2. npm install react-native-image-picker@0.28.0
    3. 使用 react-native 链接 react-native-image-picker 链接
    4. 在 ios 文件夹中安装 pod
      这里是链接:link


    【讨论】:

      【解决方案2】:

      这些步骤对我有用,使用当前版本 1.0.2 的 react-native-image-picker 和运行 iPhone X - 12.4 的 iOS 模拟器 10.3:

      npm install
      react-native link react-native-image-picker
      cd ios && pod install
      cd ../ && react-native run-ios
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-21
        • 2017-10-11
        • 1970-01-01
        • 2021-01-05
        • 2018-09-17
        相关资源
        最近更新 更多