英文:
React-Native-Image-Picker Dialog automatically closes after launching in IOS
问题
描述
我正在使用React-Native-Image-Picker来从我的应用程序中选择和上传文件。我面临的问题是,它在Android上可以正常工作,但在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.
How to repeat issue and example
import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
var options = {
title: 'Select Image',
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('Image should be less than 5 MB');
}
}).catch((err) => {});
});
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) => {
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) => {
//close the modal here
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论