Post

Replies

Boosts

Views

Activity

Reply to AVCaptureSession preview briefly goes blank after interruption (lock/unlock or camera switch) while isRunning == true
Update / Resolution In my case, the flashing preview was not a capture pipeline issue, but a SwiftUI view lifecycle issue. The camera preview was conditionally shown using: authorized && session.isRunning && cameraReady During lock/unlock or camera switches, SwiftUI re-evaluates this condition multiple times. AVCaptureSession.isRunning can briefly fluctuate during interruption recovery, causing SwiftUI to: remove the preview view show a placeholder immediately reinsert the preview This rapid view swapping appeared as a “blank flash”. The preview layer itself was fine. Fix I removed session.isRunning from the SwiftUI visibility condition. The logic is now: authorized && cameraReady cameraReady is set once after initial setup and never toggles during interruptions. The preview view stays mounted at all times. Why this works AVCaptureVideoPreviewLayer already handles short “no frames” periods gracefully. By keeping the preview layer mounted and avoiding view teardown, the flashing disappears. Takeaway AVCaptureSession.isRunning is not a reliable signal for SwiftUI view visibility Avoid mounting/unmounting camera preview views based on volatile session state After this change, the preview no longer flashes after lock/unlock or camera switches
3w