React-native-image-picker: App Crashes after photo selection (iOS 13)

Created on 23 Sep 2019  ·  27Comments  ·  Source: react-native-image-picker/react-native-image-picker

Bug

  1. Click on Choose Photo (iOS Simulator (iOS 13))
  2. Select Photo
  3. App crashes

Is this possible a permissions issue? I'm able to select the photo, but then the app crashes immediately after that and console.log(response) logs undefined

Environment info

OS
iOS 13

    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
    Memory: 4.05 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.9.1 - /usr/local/bin/node
    npm: 6.10.2 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Libraries:

    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-image-picker": "^1.1.0",

Steps To Reproduce

  1. Click on Choose Photo (iOS Simulator)
  2. Select Photo
  3. App crashes

Reproducible sample code

  addPhoto = () => {
    try {
      // Image Picker
      ImagePicker.showImagePicker(response => {
        console.log(response);
      });
    }
    catch (error) {
      console.log(error);
    }
  }
stale

Most helpful comment

@jefelewis
here's mine
```
NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSLocationWhenInUseUsageDescription

NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery

All 27 comments

Having the same with Samsung Galaxy S8 running Android 9

I have the same Issue using the above mentioned RN & Library versions, running on a simulated Nexus 6P on Android 9. The app crashes immediately after either taking a picture with the camera and confirming it, or selecting any image from the gallery.

I am able re-hydrate my App;- and Navigation state, also containg the selected/taken image, as the Promise returned by .showImagePicker() does resolve succesfully before the crash.

the Promise returned by .showImagePicker() does resolve succesfully before the crash.

Would you kindly elaborate? Because I'm pretty positive .showImagePicker does not return a Promise.

I resolved this issue successfully. You can add some value below to info.plist
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery
NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)

I resolved this issue successfully. You can add some value below to info.plist
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery
NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)

The app is still crashing after the photo selection and with the items added to info.plst as the following. Are you on iOS 13?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LastAccessedDate</key>
    <date>2019-09-23T06:56:55Z</date>
    <key>WorkspacePath</key>
    <string>/Users/jefflewis/Documents/Computer-Programming/Projects-Mobile-Apps/imagePickerTest/ios/imagePickerTest.xcworkspace</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) would like access to your photo gallery</string>
    <key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your camera</string>
    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your microphone (for videos)</string>
</dict>
</plist>

the Promise returned by .showImagePicker() does resolve succesfully before the crash.

Would you kindly elaborate? Because I'm pretty positive .showImagePicker does not return a Promise.

My bad, you're right, it does not return a promise. What I should have said is: the callback that gets handed the response is called correctly, the .error and .didCancel fields are not populated and the response object has the expected fields.

We have moved on to react-native-image-crop picker yesterday, which was reported to face the same crashing behaviour after photo selection. We were able to resolve this issue (using the crop picker library) by fixing our react-navigation setup.
In development, we were telling the navigator to place the currently developed screen on top (and skip building a correct navigation history), and the one developed at the moment was a modal. It seems the app couldnt correctly redirect after opening gallery / camera. Testing it with react-navigation setup as it would be in production, the image picking worked flawlessly.

Having the same issue. Any working fix for this?

Tested on iOS 12.4
```
"react": "16.8.3",
"react-native": "0.59.10",
"react-native-image-picker": "^1.1.0",

I resolved this issue successfully. You can add some value below to info.plist
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery
NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)

The app is still crashing after the photo selection and with the items added to info.plst as the following. Are you on iOS 13?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>LastAccessedDate</key>
  <date>2019-09-23T06:56:55Z</date>
  <key>WorkspacePath</key>
  <string>/Users/jefflewis/Documents/Computer-Programming/Projects-Mobile-Apps/imagePickerTest/ios/imagePickerTest.xcworkspace</string>
  <key>NSPhotoLibraryUsageDescription</key>
  <string>$(PRODUCT_NAME) would like access to your photo gallery</string>
  <key>NSCameraUsageDescription</key>
  <string>$(PRODUCT_NAME) would like to use your camera</string>
  <key>NSPhotoLibraryAddUsageDescription</key>
  <string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
  <key>NSMicrophoneUsageDescription</key>
  <string>$(PRODUCT_NAME) would like to use your microphone (for videos)</string>
</dict>
</plist>

I followed this, then run one time by using Xcode to compile
then it will not crash again

This error shows why app crashes (in xcode):

2019-09-27 12:51:33.564831+0300 guard[13661:149734] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
(lldb)

Adding the permissions for both iOS and Android fixed it for me.

Adding the permissions for both iOS and Android fixed it for me.

Do your permissions look like this?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LastAccessedDate</key>
    <date>2019-09-23T06:56:55Z</date>
    <key>WorkspacePath</key>
    <string>/Users/jefflewis/Documents/Computer-Programming/Projects-Mobile-Apps/imagePickerTest/ios/imagePickerTest.xcworkspace</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) would like access to your photo gallery</string>
    <key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your camera</string>
    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your microphone (for videos)</string>
</dict>
</plist>

@jefelewis
here's mine
```
NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSLocationWhenInUseUsageDescription

NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery

i am still facing this issue after adding these permission in info.list @sgimmai

@FluxProjects786 Try deleting the ios build folder restarting the bundler after adding those lines.

im having same issue, i added the permissions to info.plist but log sais

errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

any advice?

I have the same issue. I added the key in the info.plist and re-run every thing.

I figured that the app crash on iOS 13, but it works fine on iOS 12.

Any idea ?

If the app is crashing after choosing a photo from iOS simulator gallery, I suppose it is caused because is a high quality image and there is a limit... when my app crashes, this "error" appears in Xcode:
libsystem_kernel.dylib`__abort_with_payload:
Captura de Tela 2019-12-06 às 13 35 04

I don't know if it makes sense...

how to fix issue @pedromelo98 ?

@DoanDat2511 I didn’t try yet but there are some
libraries that reduces the size of the images, so if this is the problem, I think that could be a possible solution.

thanks you very much !

Vào Th 3, 7 thg 1, 2020 vào lúc 08:13 pedromelo98 <
[email protected]> đã viết:

@DoanDat2511 https://github.com/DoanDat2511 I didn’t try yet but there
are some
libraries that reduces the size of the images, so if the problem is the
size of the inages I think that could be a possible solution.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/react-native-community/react-native-image-picker/issues/1178?email_source=notifications&email_token=AL7YINKKP6JSX2WIQO6HUELQ4PJM3A5CNFSM4IZF4WJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIHK7JA#issuecomment-571387812,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AL7YINJZ2BNPYU4ILOVNASDQ4PJM3ANCNFSM4IZF4WJQ
.

Hello all,

As per above recommendation you have to do following:

  1. Open Info.plist located in ios/{NAME_OF_YOUR_PROJECT}/Info.plist
  2. Add following keys related to PhotoLibrary usage:

    NSPhotoLibraryAddUsageDescription
    $(PRODUCT_NAME) would like to save photos to your photo gallery
    NSPhotoLibraryUsageDescription
    $(PRODUCT_NAME) would like access to your photo gallery
    NSLocationWhenInUseUsageDescription

Example:





NSCameraUsageDescription
$(PRODUCT_NAME) would like to use your camera
NSMicrophoneUsageDescription
$(PRODUCT_NAME) would like to use your microphone (for videos)
NSPhotoLibraryAddUsageDescription
$(PRODUCT_NAME) would like to save photos to your photo gallery
NSPhotoLibraryUsageDescription
$(PRODUCT_NAME) would like access to your photo gallery

IOS 13, Iphone 11 simulator

  1. Save the file
  2. Re-run the react-native run-ios command or Run -> Build on Xcode
  3. Now you are good to go

BR,
Zhi

after crash the app debugger console show this.

2020-02-03 12:47:33.172049+0530 ActivityQ[22244:116023] [MC] Reading from private effective user settings.
2020-02-03 12:48:18.860777+0530 ActivityQ[22244:116798] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
2020-02-03 12:48:19.458140+0530 ActivityQ[22244:116023] [Common] _BSMachError: port 31c03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2020-02-03 12:48:19.458658+0530 ActivityQ[22244:116023] [Common] _BSMachError: port 31c03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2020-02-03 12:48:19.593 [error][tid:com.facebook.react.JavaScript] TypeError: null is not an object (evaluating 's.fileName.substring')
2020-02-03 12:48:19.595 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: TypeError: null is not an object (evaluating 's.fileName.substring')
2020-02-03 12:48:19.741593+0530 ActivityQ[22244:116155]
Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: TypeError: null is not an object (evaluating 's.fileName.substring')', reason: 'Unhandled JS Exception: TypeError: null is not an object (evaluating 's.fileName.substring'), stack:
@917:10856
value@25:3982
@25:1163
value@25:2939
value@25:1133
value@:
'
First throw call stack:
(
0 CoreFoundation 0x0000000106c061bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000104e4d735 objc_exception_throw + 48
2 ActivityQ 0x00000001032091df RCTFormatError + 0
3 ActivityQ 0x00000001032841bc -[RCTExceptionsManager reportFatalException:stack:exceptionId:] + 537
4 CoreFoundation 0x0000000106c0d03c __invoking___ + 140
5 CoreFoundation 0x0000000106c0a4d5 -[NSInvocation invoke] + 325
6 CoreFoundation 0x0000000106c0a926 -[NSInvocation invokeWithTarget:] + 54
7 ActivityQ 0x000000010323f661 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 612
8 ActivityQ 0x0000000103241c13 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 251
9 ActivityQ 0x0000000103241995 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
10 libdispatch.dylib 0x0000000109ba8595 _dispatch_call_block_and_release + 12
11 libdispatch.dylib 0x0000000109ba9602 _dispatch_client_callout + 8
12 libdispatch.dylib 0x0000000109bb0b0b _dispatch_lane_serial_drain + 791
13 libdispatch.dylib 0x0000000109bb1784 _dispatch_lane_invoke + 428
14 libdispatch.dylib 0x0000000109bbb89a _dispatch_workloop_worker_thread + 733
15 libsystem_pthread.dylib 0x0000000109f94fd2 _pthread_wqthread + 980
16 libsystem_pthread.dylib 0x0000000109f94be9 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@RonakPatel0 thanks for the logs, is it for ios 13??

@RonakPatel0 thanks for the logs, is it for ios 13??

Yes.

@RonakPatel0 thanks for the logs, is it for ios 13??

Yes.

I fix this issue here I get fileName _null_ so take a
fileName = res.uri.substring(res.uri.lastIndexof('-')+1)

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.

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

Was this page helpful?
0 / 5 - 0 ratings