我正在尝试使用 expo 图像选择器上传图像,但是当单击按钮并选择图像时,它会给出未处理的承诺拒绝 _expo.default.launchImageLibraryAsync 错误
已在 app json 中添加相机存储权限
import React from 'react';
import { StyleSheet, Text, TouchableOpacity, View, Image } from 'react-native';
import Expo from 'expo';
import ImagePicker from 'expo';
import * as Permissions from 'expo-permissions';
export default class App extends React.Component {
state = {
image: null,
};
selectPicture = async () => {
await Permissions.askAsync(Permissions.CAMERA_ROLL);
const { cancelled, uri } = await ImagePicker.launchImageLibraryAsync({
aspect: 1,
allowsEditing: true,
});
if (!cancelled) this.setState({ image: uri });
};
takePicture = async () => {
await Permissions.askAsync(Permissions.CAMERA);
const { cancelled, uri } = await ImagePicker.launchCameraAsync({
allowsEditing: false,
});
this.setState({ image: uri });
};
render() {
return (
<View style={styles.container}>
<Image style={styles.image} source={{ uri: this.state.image }} />
<View style={styles.row}>
<Button onPress={this.selectPicture}>Gallery</Button>
<Button onPress={this.takePicture}>Camera</Button>
</View>
</View>
);
}
}
const Button = ({ onPress, children }) => (
<TouchableOpacity style={styles.button} onPress={onPress}>
<Text style={styles.text}>{children}</Text>
</TouchableOpacity>
);
想上传图片