Skip to content

Commit

Permalink
Merge pull request #102 from bennokress/feature/89-use-ultrawide-camera
Browse files Browse the repository at this point in the history
Use the Ultra WIde Camera per default if available
  • Loading branch information
nathanfallet authored Mar 9, 2023
2 parents d8f10d9 + 6e31144 commit 65cd76b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/CodeScanner/CodeScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
shouldVibrateOnSuccess: Bool = true,
isTorchOn: Bool = false,
isGalleryPresented: Binding<Bool> = .constant(false),
videoCaptureDevice: AVCaptureDevice? = AVCaptureDevice.default(for: .video),
videoCaptureDevice: AVCaptureDevice? = AVCaptureDevice.bestForVideo,
completion: @escaping (Result<ScanResult, ScanError>) -> Void
) {
self.codeTypes = codeTypes
Expand Down
11 changes: 11 additions & 0 deletions Sources/CodeScanner/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,14 @@ extension CodeScannerView.ScannerViewController: AVCapturePhotoCaptureDelegate {
}

}

@available(macCatalyst 14.0, *)
public extension AVCaptureDevice {

/// This returns the Ultra Wide Camera on capable devices and the default Camera for Video otherwise.
static var bestForVideo: AVCaptureDevice? {
let deviceHasUltraWideCamera = !AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInUltraWideCamera], mediaType: .video, position: .back).devices.isEmpty
return deviceHasUltraWideCamera ? AVCaptureDevice.default(.builtInUltraWideCamera, for: .video, position: .back) : AVCaptureDevice.default(for: .video)
}

}

0 comments on commit 65cd76b

Please sign in to comment.