我有一个项目,我需要将图像上传或捕获到服务器,因此我将软件包imagePicker安装到项目中,但是当我尝试使用属性ShowimagePicker时,我会收到错误"无法读取未定义的属性" ShowImagePicker"
我尝试更改版本,但行不通。我目前有:
-Android Studio虚拟设备我使用Android 8.0
创建手机- " expo":"^ 32.0.0",
- "反应":" 16.5.0",
- " react-native":" https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
- " react-native-image-picker":"^ 0.26.7" btw"^ 0.24.0"。
我尝试修改android-settings.gradle:
包括':反应形象图片'project(':react-nimative-image-picker')。projectdir = new file(rootproje)ct.projectdir,'../node_modules/react-native-inative-image-picker/android')
和in andoidManifest.xml我放置:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
imagepicker.showimagepicker(选项,(响应)=> {
if (response.didCancel) {
console.log('User cancelled photo picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else {
console.log('imagen', response)
let source = { uri: response.uri, uriOri:response.origURL, data:
response.data };
let item = {
data:response.data,
test:'test123',
source: source
}
var {cantImg} = this.state
if(this.state.avatarSource1 == null){
this.setState({avatarSource1: source})
cantImg++
console.log(cantImg)
}else if(this.state.avatarSource2 == null)
{
this.setState({ avatarSource2: source })
cantImg++
console.log(cantImg)
}else if(this.state.avatarSource3 == null)
{
this.setState({ avatarSource3: source })
cantImg++
console.log(cantImg)
}
this.setState({ cantImg: cantImg })
this.refs.x.focus()
const dismissKeyboard = require('dismissKeyboard');
dismissKeyboard();
Keyboard.dismiss()
}
});
我当前收到错误的"无法读取属性的'showimagepicker''''nordefined'
这是一个屏幕:https://prnt.sc/ml7qi1
i"解决"问题只是将Imagapicker代码从React-Native将Imagapicker代码修改为Expo Image-Picker,如果您想更多信息,这是文档https://docs.expo.io/版本/最新/sdk/imagepicker/
我通过更新我的导入来修复它:
import * as ImagePicker from 'react-native-image-picker';
ImagePicker.showImagePicker(options, (response) => {
// code here
};
它对我有用