[英]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.