From 2fd59a93e95a40295cb694b07a2b89fb6cd74d86 Mon Sep 17 00:00:00 2001 From: kate-signal Date: Tue, 24 Jun 2025 15:54:35 -0700 Subject: [PATCH] Handle session interrupts for AVCaptureSession --- .../Photos/PhotoCaptureViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift b/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift index c2ba75927f..7a1b730c1f 100644 --- a/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift +++ b/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift @@ -130,6 +130,13 @@ class PhotoCaptureViewController: OWSViewController, OWSNavigationChildControlle cameraCaptureSession.updateVideoPreviewConnection(toOrientation: previewOrientation) updateIconOrientations(isAnimated: false, captureOrientation: previewOrientation) + NotificationCenter.default.addObserver( + self, + selector: #selector(sessionWasInterrupted), + name: AVCaptureSession.wasInterruptedNotification, + object: nil + ) + resumePhotoCapture() if let dataSource = dataSource, dataSource.numberOfMediaItems > 0 { @@ -1520,6 +1527,18 @@ extension PhotoCaptureViewController: CameraCaptureSessionDelegate { func cameraCaptureSession(_ session: CameraCaptureSession, didFinishFocusingAt focusPoint: CGPoint) { completeFocusAnimation(forFocusPoint: focusPoint) } + + @objc + func sessionWasInterrupted(notification: Notification) { + if let userInfo = notification.userInfo { + guard let reasonValue = userInfo[AVCaptureSessionInterruptionReasonKey] as? NSNumber, + let reason = AVCaptureSession.InterruptionReason(rawValue: reasonValue.intValue) else { + Logger.info("session was interrupted for no apparent reason") + return + } + Logger.info("session was interrupted with reason code: \(reason.rawValue)") + } + } } private protocol TextStoryComposerViewDelegate: AnyObject {