Skip to content

Commit 65cd76b

Browse files
authored
Merge pull request #102 from bennokress/feature/89-use-ultrawide-camera
Use the Ultra WIde Camera per default if available
2 parents d8f10d9 + 6e31144 commit 65cd76b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/CodeScanner/CodeScanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
8383
shouldVibrateOnSuccess: Bool = true,
8484
isTorchOn: Bool = false,
8585
isGalleryPresented: Binding<Bool> = .constant(false),
86-
videoCaptureDevice: AVCaptureDevice? = AVCaptureDevice.default(for: .video),
86+
videoCaptureDevice: AVCaptureDevice? = AVCaptureDevice.bestForVideo,
8787
completion: @escaping (Result<ScanResult, ScanError>) -> Void
8888
) {
8989
self.codeTypes = codeTypes

Sources/CodeScanner/ScannerViewController.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,14 @@ extension CodeScannerView.ScannerViewController: AVCapturePhotoCaptureDelegate {
524524
}
525525

526526
}
527+
528+
@available(macCatalyst 14.0, *)
529+
public extension AVCaptureDevice {
530+
531+
/// This returns the Ultra Wide Camera on capable devices and the default Camera for Video otherwise.
532+
static var bestForVideo: AVCaptureDevice? {
533+
let deviceHasUltraWideCamera = !AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInUltraWideCamera], mediaType: .video, position: .back).devices.isEmpty
534+
return deviceHasUltraWideCamera ? AVCaptureDevice.default(.builtInUltraWideCamera, for: .video, position: .back) : AVCaptureDevice.default(for: .video)
535+
}
536+
537+
}

0 commit comments

Comments
 (0)