react-native-image-picker icon indicating copy to clipboard operation
react-native-image-picker copied to clipboard

LaunchImageLibrary doesn't launch image picker after multiple uses

Open whiffsalot opened this issue 9 years ago • 15 comments

Description

launchImageLibrary() seems to only return a response 1 time on IOS. It works as it should, opens up the library and then returns a selected image. After the first successful image, trying to launch the library again doesn't work. The response never arrives, image picking library never opens.

How to repeat issue and example

const options = {
  mediaType: 'photo',
  quality: 0.7,
  noData: Platform.OS !== 'ios',
};

console.log(options); // This prints

ImagePicker.launchImageLibrary(options, results => {
  console.log(results); // This gets called once, doesn't work afterwards, image library never 
  opens.
  ... 
}

Additional Information

  • React Native version: 0.45.1
  • Platform: iOS
  • Development Operating System: Mac
  • Dev tools: XCode 9.1, IOS 11.1

whiffsalot avatar Nov 13 '17 19:11 whiffsalot

Same issue here, since I updated to iOS 11

ChristiaanHaas avatar Dec 05 '17 14:12 ChristiaanHaas

I was also on iOS 11. Wasn't able to solve this issue, but react-native-image-crop-picker seemed to do the trick for me.

whiffsalot avatar Dec 13 '17 06:12 whiffsalot

I have the same problem also

mreda7 avatar Jan 16 '18 15:01 mreda7

Current workaround is to use ImagePicker.showImagePicker(...) on iOS in stead of ImagePicker.launchImageLibrary(...).

ChristiaanHaas avatar May 23 '18 13:05 ChristiaanHaas

I'm the same problem

gaoxuan-haxibiao avatar Jul 05 '18 02:07 gaoxuan-haxibiao

I get the same issue no matter which function I use @ChristiaanHaas

It appears to be an issue with this bit of code:

    void (^showPickerViewController)() = ^void() {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIViewController *root = RCTPresentedViewController();
            [root presentViewController:self.picker animated:YES completion:nil];
        });
    };

RCTPresentedViewController does return a view but calling presentViewController doesn't appear to be doing anything after it's been called once before. Maybe it's something to do with how it's cleaned up after it's closed? Not sure I'm no iOS expert.

jcurtis avatar Oct 03 '18 17:10 jcurtis

react-native-image-crop-picker appears to have the exact same issue. I'm running RN 0.54.0.

jcurtis avatar Oct 03 '18 17:10 jcurtis

Still getting this issue. Anyone found a workaround or something? Only happens in iOS.

ketnatnoon avatar Nov 29 '18 14:11 ketnatnoon

any solution ?

RZulfikri avatar Dec 20 '18 13:12 RZulfikri

This was happening to me when I had an update in the component right after calling launchImageLibrary. When I call it from a button click, it works, but when I call from a modal that is dismissed after calling it, the picker does not open or opens for a second and gets hidden.

mateuspiresl avatar May 30 '19 19:05 mateuspiresl

I had same problem on iOS (didn't test android yet) for me it work to set the permissions in the Info.plist maually:

open Info.plist under ios/YOUR_PROJECT_NAME and add:

<dict>
...
<key>NSPhotoLibraryUsageDescription</key>
    <string>YOUR_REASON_FOR_USING_USER_PHOTOS_HERE</string>
    <key>NSCameraUsageDescription</key>
    <string>YOUR_REASON_FOR_USING_USER_CAMERA_HERE</string>
</dict> 

if you want to allow videos you should also add

NSMicrophoneUsageDescription

on android you can add permissions in the Manifest.xml. You will need the following (as I said didn't test if there is an issue on android)

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

tobzilla90 avatar Jul 21 '19 10:07 tobzilla90

@mateuspiresl was right! The closing modal causes this issue. I have a custom action sheet which is implemented via Modal, and when I call launchImageLibrary and close modal at the same time, library gets opened only for the first time (and callback is getting invoked only once as well). Then I need to restart the app to be able to open gallery one more time. To fix this I have simply delayed launching gallery until modal will get closed, and everything works like a charm!

sergeylaptev avatar Jul 23 '19 16:07 sergeylaptev

@sergeylaptev Thanks, just close modal and give a little delay which works on IOS (No such issue on my Android)

SamuelGuNUAA avatar Aug 15 '19 04:08 SamuelGuNUAA

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Oct 14 '19 04:10 stale[bot]

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

stale[bot] avatar Oct 21 '19 05:10 stale[bot]