Last active
January 25, 2019 16:15
-
-
Save danielCarlosCE/f7aac3072be68b1dc1d9a6066ba70969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override init() { | |
super.init() | |
//Make sure the device can handle video | |
guard let videoDevice = AVCaptureDevice.default(for: .video), | |
let deviceInput = try? AVCaptureDeviceInput(device: videoDevice) else { | |
return | |
} | |
//session | |
captureSession = AVCaptureSession() | |
//input | |
captureSession?.addInput(deviceInput) | |
//output | |
let captureMetadataOutput = AVCaptureMetadataOutput() | |
captureSession?.addOutput(captureMetadataOutput) | |
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main) | |
//interprets qr codes only | |
captureMetadataOutput.metadataObjectTypes = [.qr] | |
//preview | |
guard let captureSession = captureSession else { return } | |
let captureVideoPreview = AVCaptureVideoPreviewLayer(session: captureSession) | |
captureVideoPreview.videoGravity = .resizeAspectFill | |
self.videoPreview = captureVideoPreview | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment