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(