diff --git a/QRCodeReader/Classes/Core/QRCodeReader.swift b/QRCodeReader/Classes/Core/QRCodeReader.swift index 7063585..04b23dd 100644 --- a/QRCodeReader/Classes/Core/QRCodeReader.swift +++ b/QRCodeReader/Classes/Core/QRCodeReader.swift @@ -61,6 +61,8 @@ open class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate { super.init() + configureDefaultDevice() + sessionQueue.async { self.configureDefaultComponents() } @@ -141,6 +143,9 @@ open class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate { // MARK: - Private Methods private func configureDefaultComponents() { + if #available(iOS 9.0, *) { + session.sessionPreset = .hd4K3840x2160 + } for output in session.outputs { session.removeOutput(output) @@ -160,6 +165,28 @@ open class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate { session.commitConfiguration() } + + private func configureDefaultDevice() { + guard let device = defaultDevice else { return } + + do { + try device.lockForConfiguration() + + if device.isAutoFocusRangeRestrictionSupported { + device.autoFocusRangeRestriction = .near + } + + if device.isFocusModeSupported(.continuousAutoFocus) { + device.focusMode = .continuousAutoFocus + } + + if device.isLowLightBoostSupported { + device.automaticallyEnablesLowLightBoostWhenAvailable = true + } + + device.unlockForConfiguration() + } catch _ { } + } // MARK: - AVCaptureMetadataOutputObjectsDelegate