Updating to Xcode 9 and Swift 4 #105
This commit is contained in:
parent
af3cef392c
commit
f7f387d031
|
@ -1 +1 @@
|
||||||
3.1
|
4.0
|
||||||
|
|
|
@ -305,24 +305,24 @@
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 0700;
|
LastSwiftUpdateCheck = 0700;
|
||||||
LastUpgradeCheck = 0820;
|
LastUpgradeCheck = 0900;
|
||||||
ORGANIZATIONNAME = "Yannick Loriot";
|
ORGANIZATIONNAME = "Yannick Loriot";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
CE412E8819D9A1E4000F294E = {
|
CE412E8819D9A1E4000F294E = {
|
||||||
CreatedOnToolsVersion = 6.0.1;
|
CreatedOnToolsVersion = 6.0.1;
|
||||||
DevelopmentTeam = WNK46V33W9;
|
DevelopmentTeam = WNK46V33W9;
|
||||||
LastSwiftMigration = 0800;
|
LastSwiftMigration = 0900;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
};
|
};
|
||||||
CE412E9D19D9A1E4000F294E = {
|
CE412E9D19D9A1E4000F294E = {
|
||||||
CreatedOnToolsVersion = 6.0.1;
|
CreatedOnToolsVersion = 6.0.1;
|
||||||
LastSwiftMigration = 0800;
|
LastSwiftMigration = 0900;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
TestTargetID = CE412E8819D9A1E4000F294E;
|
TestTargetID = CE412E8819D9A1E4000F294E;
|
||||||
};
|
};
|
||||||
CE8FFED51BAB4E7F00D43F38 = {
|
CE8FFED51BAB4E7F00D43F38 = {
|
||||||
CreatedOnToolsVersion = 7.0;
|
CreatedOnToolsVersion = 7.0;
|
||||||
LastSwiftMigration = 0800;
|
LastSwiftMigration = 0900;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -471,14 +471,20 @@
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
@ -518,14 +524,20 @@
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
@ -560,7 +572,7 @@
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
|
@ -576,7 +588,7 @@
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
@ -598,7 +610,7 @@
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/QRCodeReader.swift.app/QRCodeReader.swift";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/QRCodeReader.swift.app/QRCodeReader.swift";
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
|
@ -618,7 +630,7 @@
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/QRCodeReader.swift.app/QRCodeReader.swift";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/QRCodeReader.swift.app/QRCodeReader.swift";
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
|
@ -641,7 +653,7 @@
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.yannickloriot.QRCodeReader;
|
PRODUCT_BUNDLE_IDENTIFIER = com.yannickloriot.QRCodeReader;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
VERSION_INFO_PREFIX = "";
|
VERSION_INFO_PREFIX = "";
|
||||||
};
|
};
|
||||||
|
@ -667,7 +679,7 @@
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_VERSION = 4.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
VERSION_INFO_PREFIX = "";
|
VERSION_INFO_PREFIX = "";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0820"
|
LastUpgradeVersion = "0900"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
</Testables>
|
</Testables>
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|
|
@ -32,7 +32,7 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
||||||
lazy var reader: QRCodeReader = QRCodeReader()
|
lazy var reader: QRCodeReader = QRCodeReader()
|
||||||
lazy var readerVC: QRCodeReaderViewController = {
|
lazy var readerVC: QRCodeReaderViewController = {
|
||||||
let builder = QRCodeReaderViewControllerBuilder {
|
let builder = QRCodeReaderViewControllerBuilder {
|
||||||
$0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObjectTypeQRCode], captureDevicePosition: .back)
|
$0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: .back)
|
||||||
$0.showTorchButton = true
|
$0.showTorchButton = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +124,7 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func reader(_ reader: QRCodeReaderViewController, didSwitchCamera newCaptureDevice: AVCaptureDeviceInput) {
|
func reader(_ reader: QRCodeReaderViewController, didSwitchCamera newCaptureDevice: AVCaptureDeviceInput) {
|
||||||
if let cameraName = newCaptureDevice.device.localizedName {
|
print("Switching capturing to: \(newCaptureDevice.device.localizedName)")
|
||||||
print("Switching capturing to: \(cameraName)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readerDidCancel(_ reader: QRCodeReaderViewController) {
|
func readerDidCancel(_ reader: QRCodeReaderViewController) {
|
||||||
|
|
|
@ -29,15 +29,15 @@ import AVFoundation
|
||||||
|
|
||||||
/// Reader object base on the `AVCaptureDevice` to read / scan 1D and 2D codes.
|
/// Reader object base on the `AVCaptureDevice` to read / scan 1D and 2D codes.
|
||||||
public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate {
|
public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate {
|
||||||
var defaultDevice: AVCaptureDevice = .defaultDevice(withMediaType: AVMediaTypeVideo)
|
var defaultDevice: AVCaptureDevice = AVCaptureDevice.default(for: AVMediaType.video)!
|
||||||
var frontDevice: AVCaptureDevice? = {
|
var frontDevice: AVCaptureDevice? = {
|
||||||
if #available(iOS 10, *) {
|
if #available(iOS 10, *) {
|
||||||
return AVCaptureDevice.defaultDevice(withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .front)
|
return AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .front)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for device in AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) {
|
for device in AVCaptureDevice.devices(for: AVMediaType.video) {
|
||||||
if let _device = device as? AVCaptureDevice , _device.position == AVCaptureDevicePosition.front {
|
if device.position == AVCaptureDevice.Position.front {
|
||||||
return _device
|
return device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
return AVCaptureVideoPreviewLayer(session: self.session)
|
return AVCaptureVideoPreviewLayer(session: self.session)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// An array of strings identifying the types of metadata objects to process.
|
/// An array of object identifying the types of metadata objects to process.
|
||||||
public let metadataObjectTypes: [String]
|
public let metadataObjectTypes: [AVMetadataObject.ObjectType]
|
||||||
|
|
||||||
// MARK: - Managing the Code Discovery
|
// MARK: - Managing the Code Discovery
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
public var didFindCode: ((QRCodeReaderResult) -> Void)?
|
public var didFindCode: ((QRCodeReaderResult) -> Void)?
|
||||||
|
|
||||||
/// Block is executed when a found metadata object string could not be decoded.
|
/// Block is executed when a found metadata object string could not be decoded.
|
||||||
public var didFailDecoding: ((Void) -> Void)?
|
public var didFailDecoding: (() -> Void)?
|
||||||
|
|
||||||
// MARK: - Creating the Code Reade
|
// MARK: - Creating the Code Reade
|
||||||
|
|
||||||
|
@ -87,15 +87,15 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
Initializes the code reader with the QRCode metadata type object.
|
Initializes the code reader with the QRCode metadata type object.
|
||||||
*/
|
*/
|
||||||
public convenience override init() {
|
public convenience override init() {
|
||||||
self.init(metadataObjectTypes: [AVMetadataObjectTypeQRCode], captureDevicePosition: .back)
|
self.init(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: .back)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes the code reader with an array of metadata object types, and the default initial capture position
|
Initializes the code reader with an array of metadata object types, and the default initial capture position
|
||||||
|
|
||||||
- parameter metadataObjectTypes: An array of strings identifying the types of metadata objects to process.
|
- parameter metadataObjectTypes: An array of objects identifying the types of metadata objects to process.
|
||||||
*/
|
*/
|
||||||
public convenience init(metadataObjectTypes types: [String]) {
|
public convenience init(metadataObjectTypes types: [AVMetadataObject.ObjectType]) {
|
||||||
self.init(metadataObjectTypes: types, captureDevicePosition: .back)
|
self.init(metadataObjectTypes: types, captureDevicePosition: .back)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,17 +104,17 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
|
|
||||||
- parameter captureDevicePosition: The capture position to use on start of scanning
|
- parameter captureDevicePosition: The capture position to use on start of scanning
|
||||||
*/
|
*/
|
||||||
public convenience init(captureDevicePosition position: AVCaptureDevicePosition) {
|
public convenience init(captureDevicePosition position: AVCaptureDevice.Position) {
|
||||||
self.init(metadataObjectTypes: [AVMetadataObjectTypeQRCode], captureDevicePosition: position)
|
self.init(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: position)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes the code reader with an array of metadata object types.
|
Initializes the code reader with an array of metadata object types.
|
||||||
|
|
||||||
- parameter metadataObjectTypes: An array of strings identifying the types of metadata objects to process.
|
- parameter metadataObjectTypes: An array of objects identifying the types of metadata objects to process.
|
||||||
- parameter captureDevicePosition: The Camera to use on start of scanning.
|
- parameter captureDevicePosition: The Camera to use on start of scanning.
|
||||||
*/
|
*/
|
||||||
public init(metadataObjectTypes types: [String], captureDevicePosition: AVCaptureDevicePosition) {
|
public init(metadataObjectTypes types: [AVMetadataObject.ObjectType], captureDevicePosition: AVCaptureDevice.Position) {
|
||||||
metadataObjectTypes = types
|
metadataObjectTypes = types
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
@ -124,7 +124,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
|
|
||||||
// MARK: - Initializing the AV Components
|
// MARK: - Initializing the AV Components
|
||||||
|
|
||||||
private func configureDefaultComponents(withCaptureDevicePosition: AVCaptureDevicePosition) {
|
private func configureDefaultComponents(withCaptureDevicePosition: AVCaptureDevice.Position) {
|
||||||
session.addOutput(metadataOutput)
|
session.addOutput(metadataOutput)
|
||||||
|
|
||||||
switch withCaptureDevicePosition {
|
switch withCaptureDevicePosition {
|
||||||
|
@ -141,7 +141,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
|
|
||||||
metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
|
metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
|
||||||
metadataOutput.metadataObjectTypes = metadataObjectTypes
|
metadataOutput.metadataObjectTypes = metadataObjectTypes
|
||||||
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
|
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Switch between the back and the front camera.
|
/// Switch between the back and the front camera.
|
||||||
|
@ -154,7 +154,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
session.removeInput(_currentInput)
|
session.removeInput(_currentInput)
|
||||||
|
|
||||||
let newDeviceInput = (_currentInput.device.position == .front) ? defaultDeviceInput : _frontDeviceInput
|
let newDeviceInput = (_currentInput.device.position == .front) ? defaultDeviceInput : _frontDeviceInput
|
||||||
session.addInput(newDeviceInput)
|
session.addInput(newDeviceInput!)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
|
@ -219,7 +219,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
try defaultDevice.lockForConfiguration()
|
try defaultDevice.lockForConfiguration()
|
||||||
|
|
||||||
let current = defaultDevice.torchMode
|
let current = defaultDevice.torchMode
|
||||||
defaultDevice.torchMode = AVCaptureTorchMode.on == current ? .off : .on
|
defaultDevice.torchMode = AVCaptureDevice.TorchMode.on == current ? .off : .on
|
||||||
|
|
||||||
defaultDevice.unlockForConfiguration()
|
defaultDevice.unlockForConfiguration()
|
||||||
}
|
}
|
||||||
|
@ -294,22 +294,22 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
- returns: A boolean value that indicates whether the reader is available.
|
- returns: A boolean value that indicates whether the reader is available.
|
||||||
*/
|
*/
|
||||||
public class func isAvailable() -> Bool {
|
public class func isAvailable() -> Bool {
|
||||||
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
|
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
|
||||||
|
|
||||||
return (try? AVCaptureDeviceInput(device: captureDevice)) != nil
|
return (try? AVCaptureDeviceInput(device: captureDevice!)) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks and return whether the given metadata object types are supported by the current device.
|
Checks and return whether the given metadata object types are supported by the current device.
|
||||||
|
|
||||||
- parameter metadataTypes: An array of strings identifying the types of metadata objects to check.
|
- parameter metadataTypes: An array of objects identifying the types of metadata objects to check.
|
||||||
|
|
||||||
- returns: A boolean value that indicates whether the device supports the given metadata object types.
|
- returns: A boolean value that indicates whether the device supports the given metadata object types.
|
||||||
*/
|
*/
|
||||||
public class func supportsMetadataObjectTypes(_ metadataTypes: [String]? = nil) throws -> Bool {
|
public class func supportsMetadataObjectTypes(_ metadataTypes: [AVMetadataObject.ObjectType]? = nil) throws -> Bool {
|
||||||
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
|
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
|
||||||
|
|
||||||
let deviceInput = try AVCaptureDeviceInput(device: captureDevice)
|
let deviceInput = try AVCaptureDeviceInput(device: captureDevice!)
|
||||||
|
|
||||||
let output = AVCaptureMetadataOutput()
|
let output = AVCaptureMetadataOutput()
|
||||||
let session = AVCaptureSession()
|
let session = AVCaptureSession()
|
||||||
|
@ -321,11 +321,11 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
|
|
||||||
if metadataObjectTypes == nil || metadataObjectTypes?.count == 0 {
|
if metadataObjectTypes == nil || metadataObjectTypes?.count == 0 {
|
||||||
// Check the QRCode metadata object type by default
|
// Check the QRCode metadata object type by default
|
||||||
metadataObjectTypes = [AVMetadataObjectTypeQRCode]
|
metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
|
||||||
}
|
}
|
||||||
|
|
||||||
for metadataObjectType in metadataObjectTypes! {
|
for metadataObjectType in metadataObjectTypes! {
|
||||||
if !output.availableMetadataObjectTypes.contains(where: { $0 as! String == metadataObjectType }) {
|
if !output.availableMetadataObjectTypes.contains(where: { $0 == metadataObjectType }) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
|
|
||||||
// MARK: - AVCaptureMetadataOutputObjects Delegate Methods
|
// MARK: - AVCaptureMetadataOutputObjects Delegate Methods
|
||||||
|
|
||||||
public func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
|
public func metadataOutput(captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
|
||||||
for current in metadataObjects {
|
for current in metadataObjects {
|
||||||
if let _readableCodeObject = current as? AVMetadataMachineReadableCodeObject {
|
if let _readableCodeObject = current as? AVMetadataMachineReadableCodeObject {
|
||||||
if _readableCodeObject.stringValue != nil {
|
if _readableCodeObject.stringValue != nil {
|
||||||
|
@ -345,7 +345,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||||
stopScanning()
|
stopScanning()
|
||||||
}
|
}
|
||||||
|
|
||||||
let scannedResult = QRCodeReaderResult(value: sVal, metadataType:_readableCodeObject.type)
|
let scannedResult = QRCodeReaderResult(value: sVal, metadataType:_readableCodeObject.type.rawValue)
|
||||||
|
|
||||||
DispatchQueue.main.async(execute: { [weak self] in
|
DispatchQueue.main.async(execute: { [weak self] in
|
||||||
self?.didFindCode?(scannedResult)
|
self?.didFindCode?(scannedResult)
|
||||||
|
|
|
@ -144,7 +144,7 @@ final public class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func orientationDidChange() {
|
@objc func orientationDidChange() {
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
overlayView?.setNeedsDisplay()
|
overlayView?.setNeedsDisplay()
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class QRCodeReaderViewController: UIViewController {
|
||||||
|
|
||||||
// MARK: - Catching Button Events
|
// MARK: - Catching Button Events
|
||||||
|
|
||||||
func cancelAction(_ button: UIButton) {
|
@objc func cancelAction(_ button: UIButton) {
|
||||||
codeReader.stopScanning()
|
codeReader.stopScanning()
|
||||||
|
|
||||||
if let _completionBlock = completionBlock {
|
if let _completionBlock = completionBlock {
|
||||||
|
@ -177,13 +177,13 @@ public class QRCodeReaderViewController: UIViewController {
|
||||||
delegate?.readerDidCancel(self)
|
delegate?.readerDidCancel(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func switchCameraAction(_ button: SwitchCameraButton) {
|
@objc func switchCameraAction(_ button: SwitchCameraButton) {
|
||||||
if let newDevice = codeReader.switchDeviceInput() {
|
if let newDevice = codeReader.switchDeviceInput() {
|
||||||
delegate?.reader(self, didSwitchCamera: newDevice)
|
delegate?.reader(self, didSwitchCamera: newDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toggleTorchAction(_ button: ToggleTorchButton) {
|
@objc func toggleTorchAction(_ button: ToggleTorchButton) {
|
||||||
codeReader.toggleTorch()
|
codeReader.toggleTorch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue