diff --git a/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift b/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift index 9be33947cce..979c479be49 100644 --- a/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift +++ b/Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift @@ -66,6 +66,13 @@ class RecentSearchQRCodeScannerController: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + scannerView.cameraView.stopRunning() + } + + override func viewDidAppear(_ animated: Bool) { + if let orientation = view.window?.windowScene?.interfaceOrientation { + scannerView.cameraView.videoPreviewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation(ui: orientation) + } scannerView.cameraView.startRunning() } diff --git a/Sources/Brave/Frontend/Sync/SyncCameraView.swift b/Sources/Brave/Frontend/Sync/SyncCameraView.swift index bc152f9019c..4b5bb98f540 100644 --- a/Sources/Brave/Frontend/Sync/SyncCameraView.swift +++ b/Sources/Brave/Frontend/Sync/SyncCameraView.swift @@ -124,7 +124,7 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate { videoPreviewLayer?.frame = layer.bounds layer.addSublayer(videoPreviewLayer!) - captureSession.startRunning() + startRunning() bringSubviewToFront(cameraOverlayView) AVCaptureDevice.requestAccess( @@ -143,11 +143,19 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate { } func startRunning() { - captureSession?.startRunning() + DispatchQueue.global(qos: .default).async { [weak self] in + guard let self else { return } + + if self.captureSession?.isRunning == false { + self.captureSession?.startRunning() + } + } } func stopRunning() { - captureSession?.stopRunning() + if captureSession?.isRunning == true { + captureSession?.stopRunning() + } } func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {