React-Native-Image-Picker 在 IOS 上启动后会自动关闭对话框。

huangapple go评论78阅读模式
英文:

React-Native-Image-Picker Dialog automatically closes after launching in IOS

问题

描述

我正在使用React-Native-Image-Picker来从我的应用程序中选择和上传文件。我面临的问题是,它在Android上可以正常工作,但在iOS上,react-native-image-picker对话框在启动后会自动关闭,因此我无法选择要上传的文件。
iOS所需的所有文件上传权限也已经授予。

React-Native-Image-Picker 在 IOS 上启动后会自动关闭对话框。

如何重复问题和示例

import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';

var options = {
    title: '选择图片',
    quality: 0.25,
    storageOptions: {
        skipBackup: true,
        path: 'images',
    },
};
ImagePicker.showImagePicker(options, response => {
    console.log('Response = ', response);

    RNFetchBlob.fs.stat(response.path)
        .then((stats) => {
            if (stats.size <= 5000000) {
                let source = response;
                let checkboxStates = { ...this.state.checkboxStates };
                checkboxStates['image'] = true;

                this.setState({ imagePath: source, imageVisible: true, totalUploadSize: this.state.totalUploadSize + stats.size });
                this.setState({ checkboxStates });
            }
            else {
                toastMessage('图片应小于5MB');
            }
        }).catch((err) => { });

});

附加信息

  • React Native 版本:0.61.5
  • 平台:iOS
  • 开发操作系统:Mac OS Mojave 10.14.2
  • 开发工具:Xcode 10.14.2
  • 设备:iPad Pro (iOS 9)
英文:

Description

I am using React-Native-Image-Picker to Select and Upload Files from my App, The issue i am facing that It is working in Android but in ios react-native-image-picker dialog automically closes after launching, therefore i cannot select files for upload.
All the required permissions by ios for file upload have also been given.

React-Native-Image-Picker 在 IOS 上启动后会自动关闭对话框。

How to repeat issue and example

import ImagePicker from &#39;react-native-image-picker&#39;;
import RNFetchBlob from &#39;react-native-fetch-blob&#39;;

var options = {
      title: &#39;Select Image&#39;,
      quality : 0.25,
      storageOptions: {
        skipBackup: true,
        path: &#39;images&#39;,
      },
    };
  ImagePicker.showImagePicker(options, response =&gt; {
      console.log(&#39;Response = &#39;, response);

      RNFetchBlob.fs.stat(response.path)
      .then((stats) =&gt; {
        if (stats.size &lt;= 5000000) {
          let source = response;
          let checkboxStates = {...this.state.checkboxStates}; 
          checkboxStates[&#39;image&#39;] = true;

          this.setState({ imagePath: source, imageVisible: true, totalUploadSize: this.state.totalUploadSize + stats.size });   
          this.setState({checkboxStates});
        }
        else{
          toastMessage(&#39;Image should be less than 5 MB&#39;);
        }
      }).catch((err) =&gt; {});

    });

Additional Information

  • React Native version: 0.61.5

  • Platform: IOS

  • Development Operating System: Mac OS Mojave 10.14.2

  • Dev tools: Xcode 10.14.2

  • Device : IPad Pro (IOS 9)

答案1

得分: 7

在我的情况下,这是因为关闭图像上传选项模态框后立即打开图像选择器。尝试在给定时间内关闭,然后打开图像库,或在图像选择器启动后关闭模态框,就像这样:

ImagePicker.launchCamera(imageOptions, async (response) => {
    setModalPicker(false)
英文:

for someone who experience this, in my case this is cause of close of modal of choose option of image upload the open image picker immediately. try to close in given time then open image library or close modal after image picker launched like this :

ImagePicker.launchCamera(imageOptions, async (response) =&gt; {
          setModalPicker(false)

答案2

得分: 5

这种情况发生在具有选择相机或图库选项按钮的模态框关闭后。您可以在选择图像后关闭模态框。

ImagePicker.launchImageLibrary(options, (response) => {
    // 在这里关闭模态框
})
英文:

This happens when the modal that has the option buttons for selecting either from camera or gallery is closed. You can close the modal after selecting an image.

ImagePicker.launchImageLibrary(options, (response) =&gt; {
        //close the modal here
 })

huangapple
  • 本文由 发表于 2020年1月3日 14:51:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定