我正在尝试将包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链接react-native-image-picker,但是并不能解决问题。我需要链接另一个图书馆吗?
谢谢
答案 0 :(得分:1)
执行以下步骤:文档:link
编译并享受乐趣。
OR
尝试
降级版本
答案 1 :(得分:0)
这些步骤对我有用,使用当前版本1.0.2的react-native-image-picker和运行iPhone X-12.4的iOS Simulator 10.3:
npm install
react-native link react-native-image-picker
cd ios && pod install
cd ../ && react-native run-ios