From e7b065bb5ec207fea14a8613476b61270e50fdf9 Mon Sep 17 00:00:00 2001 From: Max Z <102792047+mxzmr@users.noreply.github.com> Date: Thu, 31 Jul 2025 10:33:58 +0300 Subject: [PATCH] fix(iPad): preserve photo orientation in landscape - Added CameraCaptureSession.setCaptureOrientation(_:) to let callers update the underlying capture orientation on the session queue. - In PhotoCaptureViewController.viewWillAppear(_:), derive the correct interface orientation on iPad and invoke the new helper, keeping the preview layer and capture pipeline in sync. Photos and videos captured while the iPad is held in landscape now embed the correct EXIF / track orientation; no more 90-degree rotation to portrait. --- .../ViewControllers/Photos/CameraCaptureSession.swift | 9 +++++++++ .../Photos/PhotoCaptureViewController.swift | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/Signal/src/ViewControllers/Photos/CameraCaptureSession.swift b/Signal/src/ViewControllers/Photos/CameraCaptureSession.swift index 3804235b63..251e8782ce 100644 --- a/Signal/src/ViewControllers/Photos/CameraCaptureSession.swift +++ b/Signal/src/ViewControllers/Photos/CameraCaptureSession.swift @@ -341,6 +341,15 @@ class CameraCaptureSession: NSObject { } private var motionManager: CMMotionManager? + + // Allows external callers to update capture orientation on the session queue. + // Useful for iPads deriving orientation from interface, especially before accelerometer data is available. + func setCaptureOrientation(_ orientation: AVCaptureVideoOrientation) { + sessionQueue.async { [weak self] in + self?.captureOrientation = orientation + self?.updateVideoCaptureOrientation() + } + } func updateVideoPreviewConnection(toOrientation orientation: AVCaptureVideoOrientation) { guard let videoConnection = previewView.previewLayer.connection else { diff --git a/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift b/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift index f21d3c06ce..6d8c4c82a6 100644 --- a/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift +++ b/Signal/src/ViewControllers/Photos/PhotoCaptureViewController.swift @@ -127,7 +127,11 @@ class PhotoCaptureViewController: OWSViewController, OWSNavigationChildControlle previewOrientation = .portrait } UIViewController.attemptRotationToDeviceOrientation() + + // Updates preview layer and capture orientation for correct media encoding. + // Crucial on iPad where interface orientation may differ from default portrait. cameraCaptureSession.updateVideoPreviewConnection(toOrientation: previewOrientation) + cameraCaptureSession.setCaptureOrientation(previewOrientation) updateIconOrientations(isAnimated: false, captureOrientation: previewOrientation) NotificationCenter.default.addObserver(