React Native - 使用图片选择器react-native-image-picker拍照、选照片

亲测有用 3.X 使用showImagePicker会报错 2.3.0也会报错
使用的react-native-image-picker@2.3.4 可以使用showImagePicker方法

yarn add react-native-image-picker@2.3.4
 #RN >= 0.60(如果你的react-native版本 > = 0.60执行以下命令)
 npx pod-install

 #RN < 0.60(如果你的react-native版本< 0.60执行以下命令)
 react-native link react-native-image-picker@2.3.4

js中使用

import ImagePicker from 'react-native-image-picker';

const options = {
    title: '请选择',
    cancelButtonTitle:'取消',
    takePhotoButtonTitle:'拍照',
    chooseFromLibraryButtonTitle:'从相册选择',
    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) {
        Alert.alert('自定义按钮:' + response.customButton)
      } else {
        const source = { uri: response.uri };
        Alert.alert(JSON.stringify(source))
        console.log("source:" + JSON.stringify(source))
      }
    });

Android:


233be4eae96875b70d3b1d7362490b0.jpg

IOS:


be082800d37bc7956f21d3fa3f346eb.jpg

参考文章https://www.cnblogs.com/freecolor/p/13992759.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容