gpt4 book ai didi

android - react native 图像选择器 showimagepicker

转载 作者:行者123 更新时间:2023-11-29 02:41:12 27 4
gpt4 key购买 nike

我想使用 react-native 图像选择器拍摄图像,我正在使用 npm run android 命令,但是当应用程序在 expo 中运行时,它显示此错误:

undefined is not an object(evaluating 'imagepickerManager.showimagepicker')

因为我正在使用 expo 项目 index.android.js 不存在于项目中所以 react-native run-android 命令不起作用。

有人可以指导我如何恢复此错误吗?

ERROR

import React, {Component} from 'react';
import {Text, View, TouchableOpacity, Image} from 'react-native';

// var ImagePicker = require('react-native-image-picker');
import * as ImagePicker from 'react-native-image-picker';
// More info on all the options is below in the README...just some common use cases shown here
var options = {
title: 'Select Avatar',
customButtons: [
{name: 'fb', title: 'Choose Photo from Facebook :'},
],
storageOptions: {
skipBackup: true,
path: 'images'
}
};

export default class App extends Component{
constructor(props){
super(props);
this.state={
avatarSource:null
}
}
render(){
let img=this.state.avatarSource == null?null:
<Image
source={this.state.avatarSource}
style={{height:200, width:300}}
/>
return(
<View>
<Text>Welcome to Image Picker</Text>
<TouchableOpacity onPress = {this.show.bind()} >
<Text>Load Images</Text>
</TouchableOpacity>
{img}
</View>
)
}
show(){
ImagePicker.showImagePicker(options, (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 please: ', response.customButton);
}
else {
let source = { uri: response.uri };

// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };

this.setState({
avatarSource: source
});
}
});
}
}

最佳答案

我遇到了同样的问题。并通过以下方式解决 -

  1. react-native 链接 react-native-image-picker
  2. 运行 react-native-run-ios 和 react-native run-android 命令

More description here

关于android - react native 图像选择器 showimagepicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43994281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com