react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

fix: iPhone 17 Pro/Pro Max crashes app when capturePhoto

Open herarya opened this issue 4 weeks ago • 3 comments

Fix iPhone 17 Pro/Pro Max crashes app when capturePhoto

What

This PR fixes a crash on iPhone 17 Pro and Pro Max devices when attempting to capture photos. The crash was caused by calling AVCapturePhotoOutput.capturePhoto(with:delegate:) when the video connection was not yet active or enabled, resulting in the error: "No active and enabled video connection".

Changes

  • Added readiness check to ensure AVCaptureSession.isRunning is true before attempting photo capture
  • Added validation to verify the video connection is both enabled and active before capture
  • Implemented auto-repair logic that re-adds AVCapturePhotoOutput and resets the session preset when the video connection is not ready
  • Added polling mechanism (max 0.5s, 50ms intervals) to handle timing races after session reconfiguration
  • Session automatically starts if not running, with a brief wait period (200ms) for initialization

Tested on

  • iPhone 17 Pro, iOS 26.x (verified fix works as expected)

https://github.com/user-attachments/assets/d4849409-8529-4de2-8883-cb0bdd1a11a5

  • iPhone 16 verified
  • iPhone 17 verified

Related issues

herarya avatar Dec 03 '25 06:12 herarya

@herarya is attempting to deploy a commit to the mrousavy's Team Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 03 '25 06:12 vercel[bot]

We just tried this and it looks promising but we are still seeing a greyed out video feed when taking a picture the first time around: Screenshot 2025-12-03 at 15 39 35

When a picture is taken and we go back to the camera to re-take another one, the image looks right: Screenshot 2025-12-03 at 15 39 52

pouyaemami avatar Dec 03 '25 14:12 pouyaemami

I've got same problem. Grayed image and crash when take photo.

Tebrynn avatar Dec 05 '25 09:12 Tebrynn