Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update QRCode.swift #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions QRCode/Source/QRCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
colorFilter.setValue(backColor, forKey: "inputColor1")

let transform = CGAffineTransform(scaleX: 10, y: 10)
let transformedImage = qrFilter.outputImage!.applying(transform)
let transformedImage = qrFilter.outputImage!.transformed(by: transform)

let image = UIImage(ciImage: transformedImage)

Expand Down Expand Up @@ -179,7 +179,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
return
}

if !session.canAddInput(videoInput) {
if !session.canAddInput(videoInput!) {
print("can not add input device")
return
}
Expand All @@ -189,7 +189,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
return
}

session.addInput(videoInput)
session.addInput(videoInput!)
session.addOutput(dataOutput)

dataOutput.metadataObjectTypes = dataOutput.availableMetadataObjectTypes;
Expand All @@ -210,7 +210,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
if currentDetectedCount > maxDetectedCount {
session.stopRunning()

completedCallBack!(codeObject.stringValue)
completedCallBack!(codeObject.stringValue!)

if autoRemoveSubLayers {
removeAllLayers()
Expand Down Expand Up @@ -274,8 +274,8 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
/// previewLayer
lazy var previewLayer: AVCaptureVideoPreviewLayer = {
let layer = AVCaptureVideoPreviewLayer(session: self.session)
layer?.videoGravity = AVLayerVideoGravityResizeAspectFill
return layer!
layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
return layer
}()

/// drawLayer
Expand All @@ -285,7 +285,7 @@ open class QRCode: NSObject, AVCaptureMetadataOutputObjectsDelegate {
/// input
lazy var videoInput: AVCaptureDeviceInput? = {

if let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) {
if let device = AVCaptureDevice.default(for: AVMediaType.video) {
return try? AVCaptureDeviceInput(device: device)
}
return nil
Expand Down