fix: iPhone 17 Pro/Pro Max crashes app when capturePhoto
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.isRunningistruebefore attempting photo capture - Added validation to verify the video connection is both enabled and active before capture
- Implemented auto-repair logic that re-adds
AVCapturePhotoOutputand 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 is attempting to deploy a commit to the mrousavy's Team Team on Vercel.
A member of the Team first needs to authorize it.
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:
When a picture is taken and we go back to the camera to re-take another one, the image looks right:
I've got same problem. Grayed image and crash when take photo.