3

我正在尝试将包 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,但它没有解决问题。我需要链接另一个库吗?

谢谢

4

2 回答 2

1

Perform this steps: document:link

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>.
  2. Go to node_modules ➜ react-native-image-picker ➜ ios ➜ select RNImagePicker.xcodeproj.
  3. Add libRNImagePicker.a to Build Phases -> Link Binary With Libraries.
  4. Refer to Post-install Steps.

Compile and have fun.

OR

try to
Downgrade version

  1. npm uninstall react-native-image-picker
  2. npm install react-native-image-picker@0.28.0
  3. Link using react-native link react-native-image-picker
  4. Do pod install inside ios folder
    Here is link :link


于 2019-08-02T06:02:08.473 回答
0

这些步骤对我有用,使用当前版本 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
于 2019-08-12T05:33:44.247 回答