无法读取未定义的react-native-image-picker的属性“launchImageLibrary”

lsi*_*lva 5 javascript react-native react-native-image-picker

我的功能提供了一个小图像图标作为可触摸的按钮来上传或拍照,使用"react-native-image-picker": "^3.3.2"

我收到 error: ,与此GitHub 问题Cannot read property 'launchImageLibrary' of undefined相同,但如您所见,我的代码已经按照他们的指示进行了导入。

这是我的完整代码:

import React from 'react';
import {
    StyleSheet,
    Image,
    TouchableOpacity,
    Alert
} from 'react-native';
import { launchImageLibrary } from 'react-native-image-picker';

const ImageUpload: React.FC<any> = ({}) => {

    function showMessage() {
        Alert.alert("Upload image", "Choose a option", [
            {
                text: 'Camera',
                onPress: () => openCamera(),
            },
            {
                text: 'Gallery',
                onPress: () => openLibrary()
            },
        ]);
    }

    const openLibrary = () => {

        const options = {
            storageOptions: {
              skipBackup: true,
              path: 'images',
            },
          };
        launchImageLibrary(options, (response) => {
            console.log(response);
        });

    }

    const openCamera = () => {
        //ongoing
    }

    return(
        <>
            <TouchableOpacity onPress={()=>showMessage()}>
                <Image source={require('./picture.png')} style={{ width: 70, height: 70 }}/>
            </TouchableOpacity>
        </>
     );
};

const style = StyleSheet.create({
    ImageIcon: {
        justifyContent: "center",
        alignItems: "center",
    }

});

export default ImageUpload;
Run Code Online (Sandbox Code Playgroud)

另外,在 VS Code 中,调用时出现此错误launchImageLibrary在此输入图像描述

我已经表演过一次了npx pod-install

小智 -4

import * as ImagePicker from 'react-native-image-picker';
Run Code Online (Sandbox Code Playgroud)