Skip to content

Commit

Permalink
Fix camera focus on QrScan view
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Nov 7, 2023
1 parent 27a4e30 commit 73a2e6f
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ class ScanQrView: UIView {
private func initialSetup() {
scanQueue.async { () in
do {
guard let videoCaptureDevice = AVCaptureDevice.default(for: AVMediaType.video) else {
self.failed()
return
let captureDevice: AVCaptureDevice

if let device = AVCaptureDevice.default(.builtInTripleCamera, for: .video, position: .back) {
captureDevice = device
} else if let device = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back) {
captureDevice = device
} else if let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) {
captureDevice = device
} else {
throw DeviceError.noBackCamera
}

let videoInput: AVCaptureDeviceInput

videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
videoInput = try AVCaptureDeviceInput(device: captureDevice)
guard self.captureSession.canAddInput(videoInput) else {
self.failed()
return
Expand Down Expand Up @@ -171,3 +179,9 @@ extension ScanQrView: AVCaptureMetadataOutputObjectsDelegate {
}
}
}

extension ScanQrView {
enum DeviceError: Error {
case noBackCamera
}
}

0 comments on commit 73a2e6f

Please sign in to comment.