图像选取器在 React Native 应用程序中不起作用,为什么? [英] Image Picker not working in React Native app, why?
问题描述
我已经成功安装了 react-native-image-picker,对于一个全新的 React Native 应用程序,将它链接起来并通过 info.plist 文件授予正确的权限以访问相机、照片等...
I've installed react-native-image-picker successfully, for a fresh react native app, linked it and given right permissions via the info.plist file to access camera, photos etc...
我在 react-native-image-picker 页面上使用自述文件中的代码,但收到错误
I'm using the code from the ReadMe on react-native-image-picker page, but i receive an error
当尝试 openGallery() 时,我收到以下警告并且没有打开图像库:
When attempting to openGallery() i get the following warning and no image library opens:
可能未处理的 Promise Rejection TypeError;undefined 不是一个函数(接近...reactNativeImagePicker.default.launchImageLibrary...)
这是我的代码:
import ImagePicker from 'react-native-image-picker';
.....
class App extends Component {
constructor(props) {
super(props)
this.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>
);
}
}
其运行的工厂锅炉板代码.怎么回事?
Its run of the mill boiler plate code. Whats going on?
@BoredKid,我在控制台日志中看到了这个:
@BoredKid, i get this in my console log:
对于(ImagePicker):
for (ImagePicker):
{showImagePicker: ƒ}
showImagePicker: ƒ showImagePicker(options, callback)
__proto__: Object
for (ImagePicker.showImagePicker);
for (ImagePicker.showImagePicker);
ƒ showImagePicker(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
return ImagePickerManager.showImagePicker((0, _objectS…
推荐答案
更新了新的输入:你的 ImagePicker
对象没有 launchImageLibrary
也没有 launchCamera代码>.你的安装有问题...也许安装没有正常工作或者你做错了一个步骤.让我们尝试重新安装,我们会看到问题仍然存在
Updated with new input: your ImagePicker
object do not have launchImageLibrary
nor launchCamera
. There is a problem with you installation ... Maybe the installation didn't work properly or there is a step you made wrong. Let's try to reinstall and we'll see it the problem persist
这篇关于图像选取器在 React Native 应用程序中不起作用,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!