Skip to content

Commit 54be20f

Browse files
committed
Bug fix for iPhone 17 pro/max mrousavy#3677
1 parent 4453edc commit 54be20f

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

package/ios/Core/CameraSession+Photo.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ extension CameraSession {
1717
func takePhoto(options: TakePhotoOptions, promise: Promise) {
1818
// Run on Camera Queue
1919
CameraQueues.cameraQueue.async {
20+
// Ensure AVCaptureSession is running
21+
if !self.captureSession.isRunning {
22+
VisionLogger.log(level: .error, message: "Capture session is not running. Attempting to start...")
23+
self.captureSession.startRunning()
24+
usleep(200_000) // 200ms
25+
if !self.captureSession.isRunning {
26+
promise.reject(error: .session(.cameraNotReady))
27+
return
28+
}
29+
}
30+
31+
// Check video connection readiness
32+
if let photoOutput = self.photoOutput,
33+
let videoConnection = photoOutput.connection(with: .video),
34+
!(videoConnection.isEnabled && videoConnection.isActive) {
35+
VisionLogger.log(level: .error, message: "No active/enabled video connection. Attempting auto-repair...")
36+
self.captureSession.beginConfiguration()
37+
self.captureSession.removeOutput(photoOutput)
38+
let newPhotoOutput = AVCapturePhotoOutput()
39+
self.captureSession.addOutput(newPhotoOutput)
40+
self.photoOutput = newPhotoOutput
41+
if self.captureSession.canSetSessionPreset(.photo) {
42+
self.captureSession.sessionPreset = .photo
43+
}
44+
self.captureSession.commitConfiguration()
45+
self.captureSession.startRunning()
46+
// Poll for video connection readiness (max 0.5s)
47+
var ready = false
48+
for _ in 0..<10 {
49+
if let conn = newPhotoOutput.connection(with: .video), conn.isEnabled, conn.isActive {
50+
ready = true
51+
break
52+
}
53+
usleep(50_000) // 50ms
54+
}
55+
if !ready {
56+
promise.reject(error: .session(.cameraNotReady))
57+
return
58+
}
59+
}
2060
// Get Photo Output configuration
2161
guard let configuration = self.configuration else {
2262
promise.reject(error: .session(.cameraNotReady))

package/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "react-native-vision-camera",
3-
"version": "4.7.1",
2+
"name": "@mai/react-native-vision-camera",
3+
"version": "4.7.4",
44
"description": "A powerful, high-performance React Native Camera library.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)