fix(ios): prevent crash when capturePhoto has no active video connection
What
This PR fixes a crash on iOS devices where calling AVCapturePhotoOutput.capturePhoto(with:delegate:) could throw:
*** -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection
The crash was caused by attempting to capture a photo when the AVCaptureSession was running but the video connection was not yet active (e.g., right after camera switch, format change, or session interruption).
Changes
- Added a readiness check before capture:
- Ensure AVCaptureSession.isRunning == true
- Ensure video connection is both enabled and active
- Added an auto-repair path:
- Re-add AVCapturePhotoOutput inside beginConfiguration/commitConfiguration
- Reset session preset to .photo if available
- Restart the session if necessary
- Added a short polling window (default 0.5s, every 50ms) to handle timing races after reconfiguration
- Preserved existing logging (VisionLogger.log) and behavior for resolution, flash, red-eye reduction, depth data, portrait effects matte, and distortion correction.
Tested on
- iPhone 17 Pro (iOS 18 beta) – verified crash no longer occurs when switching cameras rapidly and capturing immediately.
- iPhone 16 Pro (iOS 26.0) - regression check, normal behavior.
- iPhone 16 Pro (iOS 18.6) - regression check, normal behavior.
- iPhone 16 (iOS 26.0) - regression check, normal behavior.
- iPhone 12 Pro (iOS 16.x) – regression check, normal behavior.
Related issues
- Closes #3633
- Related discussions:
- https://stackoverflow.com/questions/78212727
- https://stackoverflow.com/questions/67804126
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| react-native-vision-camera | Preview | Comment | Sep 26, 2025 9:03am |
Could you please approve this update? i cannot take photo on iphone17 pro
Hello There,
Same here...we are getting reports about this... thanks in advance
+1
When can we expect it to be merged and released?
We need to know whether to patch it or wait for the official fix
Running into multiple instances of this as well. Do we have an ETA or is it worth patching ourselves?
I created a patch using this code. The camera on the iPhone 17 Pro now works, but the preview appears significantly darker than usual before capturing the photo. with this error:
session/camera-not-ready: The Camera is not ready yet! Wait for the onInitialized() callback!
at construct (native)
at apply (native)
at _construct (app:///main.jsbundle:1:255616)
at Wrapper (app:///main.jsbundle:1:255268)
at construct (native)
at _callSuper (app:///main.jsbundle:1:3318079)
at CameraError (app:///main.jsbundle:1:3318524)
at construct (native)
at _callSuper (app:///main.jsbundle:1:3318079)
at CameraRuntimeError (app:///main.jsbundle:1:3318975)
at tryParseNativeCameraError (app:///main.jsbundle:1:3319280)
at ?anon_0_ (app:///main.jsbundle:1:3314080)
at throw (native)
at asyncGeneratorStep (app:///main.jsbundle:1:727134)
at _throw (app:///main.jsbundle:1:727438)
at tryCallOne (app:///main.jsbundle:1:1181)
at anonymous (app:///main.jsbundle:1:1875)
Camera is not darker on my iphone 17 pro but foggy and desaturated.
@mrousavy is there an upcoming fix for this? it's crashing for ios 17 pros
..did you read my review comments?
..did you read my review comments?
I did but I'm not the original author. That's why I was wondering if this would be officially fixed.