我正在使用“在react-native-image-picker上的自述文件”页面中的代码,但安装成功后,我收到一条错误消息(并且我还在info.plist上设置了正确的权限。
当尝试打开openGallery()时,出现以下警告,并且没有图像库打开:
可能未处理的Promise Rejection TypeError;未定义不是函数(在... reactNativeImagePicker.default.launchImageLibrary附近)
这是我的代码:
import ImagePicker from 'react-native-image-picker';
.....
class App extends Component {
constructor(props) {
super(props)
state = {
fileURL: '',
}
}
//function
openGallery = async () => {
const options = {
mediaType: 'video'
}
ImagePicker.launchImageLibrary(options, (response) => {
console('Response = ', response);
if(response.didCancel){
console.log('User cancelled image picker');
}
else{
this.setState({ fileURL: response.uri });
}
});
}
render() {
return (
<View style={styles.container}>
<Button
style={{margin: 20}}
onPress={this.openGallery}
title='Open Gallery'
backgroundColor='blue'
/>
</View>
);
}
}
知道为什么吗?