[英]React Native Image Picker: Cannot read property 'showImagePicker' of undefined
[英]React Native Image Picker cannot read property “showImagePicker” of undefined
我已经按照所有iOS的安装说明进行了包装react-native-image-picker
showImagePicker()
,但是在我尝试使用showImagePicker()
方法时,它仍然会出错。
它告诉我它cannot read property "showImagePicker" of undefined
。
我在文件顶部导入了包var ImagePicker = require('react-native-image-picker');
,我已多次进行react-native link
,已将RNImagePicker.xcodeproj
添加到我的库文件夹,已将RNImagePicker.a
添加到“使用库链接二进制文件”,已将权限添加到我的info.plist
文件。
我已经完成了文档中的所有操作,但是仍然没有任何效果。
这是我的JS:
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, View, Image, ScrollView, TextInput, TouchableOpacity, KeyboardAvoidingView } from 'react-native';
var ImagePicker = require('react-native-image-picker');
export default class ProfilePicUploaderPage extends React.Component {
state = {
ProfilePicLocalSource: null,
ProfilePicRemoteSource: null
}
ChoosePhoto(){
console.log(SOCButton);
var options = {
title: 'Select Avatar',
customButtons: [
{name: 'fb', title: 'Choose Photo from Facebook'},
],
storageOptions: {
skipBackup: true,
path: 'images'
}
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image 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 };
this.setState({
avatarSource: source
});
}
});
}
render(){
return(<all of my JSX>);
}
关于发生的事情,我的唯一线索是,当我尝试在Xcode中构建我的应用程序时,它失败并显示错误clang: error: linker command failed with exit code 1 (use -v to see invocation)
。
有人知道发生了什么吗?
您似乎没有将ImagePicker导入到JS文件中。 尝试import ImagePicker from 'react-native-image-picker'
使用import ImagePicker from 'react-native-image-picker'
如果您正确地遵循了iOS的链接步骤,那就应该不错了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.