Bump to v7.1.0 #67 #68

This commit is contained in:
Yannick Loriot 2016-10-12 21:58:26 +02:00
parent 6967e09d22
commit d272e93155
10 changed files with 23 additions and 334 deletions

View File

@ -1,5 +1,11 @@
# Change log
## [Version 7.1.0](https://github.com/yannickl/QRCodeReader.swift/releases/tag/7.1.0)
Released on 2016-10-12.
- [ADD] Specify starting camera position in the init of `QRCodeReader` object
- [ADD] `reader:didSwitchCamera` delegate method
## [Version 7.0.1](https://github.com/yannickl/QRCodeReader.swift/releases/tag/7.0.1)
Released on 2016-09-13.

View File

@ -14,6 +14,7 @@ Please keep the list sorted.
* [Alex Kreutz](https://github.com/bbsan2k)
* [Bas Broek](https://github.com/BasThomas)
* [Cody Duncan](https://github.com/cody1024d)
* [David Crook](https://github.com/dpcrook)
* [Daniel Larsson](https://github.com/larssondaniel)
* [Daniel Tartaglia](https://github.com/dtartaglia)

View File

@ -363,12 +363,12 @@
files = (
CE4E1EE01D81838F00D2AC35 /* ToggleTorchButton.swift in Sources */,
CE4E1EDF1D81838F00D2AC35 /* SwitchCameraButton.swift in Sources */,
CE412E9119D9A1E4000F294E /* ViewController.swift in Sources */,
CE4E1EDA1D81838F00D2AC35 /* QRCodeReader.swift in Sources */,
CE4E1EDE1D81838F00D2AC35 /* ReaderOverlayView.swift in Sources */,
CE4E1EDC1D81838F00D2AC35 /* QRCodeReaderViewController.swift in Sources */,
CE4E1EDB1D81838F00D2AC35 /* QRCodeReaderResult.swift in Sources */,
CE4E1EDD1D81838F00D2AC35 /* QRCodeReaderViewControllerBuilder.swift in Sources */,
CE412E9119D9A1E4000F294E /* ViewController.swift in Sources */,
CE412E8F19D9A1E4000F294E /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>7.0.1</string>
<string>7.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@ -29,7 +29,7 @@ import AVFoundation
class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
lazy var reader = QRCodeReaderViewController(builder: QRCodeReaderViewControllerBuilder {
$0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObjectTypeQRCode], captureDevicePosition: .back)
$0.reader = QRCodeReader()
$0.showTorchButton = true
})

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>7.0.1</string>
<string>7.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'QRCodeReader.swift'
s.module_name = 'QRCodeReader'
s.version = '7.0.1'
s.version = '7.1.0'
s.license = 'MIT'
s.summary = 'Simple QRCode and 1D bar code reader in Swift'
s.homepage = 'https://github.com/yannickl/QRCodeReader.swift.git'

View File

@ -1,325 +0,0 @@
/*
* QRCodeReader.swift
*
* Copyright 2014-present Yannick Loriot.
* http://yannickloriot.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
import UIKit
import AVFoundation
/// Convenient controller to display a view to scan/read 1D or 2D bar codes like the QRCodes. It is based on the `AVFoundation` framework from Apple. It aims to replace ZXing or ZBar for iOS 7 and over.
public class QRCodeReaderViewController: UIViewController {
private var cameraView = ReaderOverlayView()
private var cancelButton: UIButton?
private var switchCameraButton: SwitchCameraButton?
private var toggleTorchButton: ToggleTorchButton?
/// The code reader object used to scan the bar code.
public let codeReader: QRCodeReader
let startScanningAtLoad: Bool
let showSwitchCameraButton: Bool
let showCancelButton: Bool
let showTorchButton: Bool
// MARK: - Managing the Callback Responders
/// The receiver's delegate that will be called when a result is found.
public weak var delegate: QRCodeReaderViewControllerDelegate?
/// The completion blocak that will be called when a result is found.
public var completionBlock: (QRCodeReaderResult? -> Void)?
deinit {
codeReader.stopScanning()
NSNotificationCenter.defaultCenter().removeObserver(self)
}
// MARK: - Creating the View Controller
/**
Initializes a view controller to read QRCodes from a displayed video preview and a cancel button to be go back.
- parameter cancelButtonTitle: The title to use for the cancel button.
- parameter startScanningAtLoad: Flag to know whether the view controller start scanning the codes when the view will appear.
:see: init(cancelButtonTitle:, metadataObjectTypes:)
*/
@available(iOS, deprecated, message = "Use init with builder instead.")
convenience public init(cancelButtonTitle: String, startScanningAtLoad: Bool = true) {
self.init(cancelButtonTitle: cancelButtonTitle, metadataObjectTypes: [AVMetadataObjectTypeQRCode], startScanningAtLoad: startScanningAtLoad)
}
/**
Initializes a reader view controller with a list of metadata object types.
- parameter metadataObjectTypes: An array of strings identifying the types of metadata objects to process.
- parameter startScanningAtLoad: Flag to know whether the view controller start scanning the codes when the view will appear.
:see: init(cancelButtonTitle:, metadataObjectTypes:)
*/
@available(iOS, deprecated, message = "Use init with builder instead.")
convenience public init(metadataObjectTypes: [String], startScanningAtLoad: Bool = true) {
self.init(cancelButtonTitle: "Cancel", metadataObjectTypes: metadataObjectTypes, startScanningAtLoad: startScanningAtLoad)
}
/**
Initializes a view controller to read wanted metadata object types from a displayed video preview and a cancel button to be go back.
- parameter cancelButtonTitle: The title to use for the cancel button.
- parameter metadataObjectTypes: An array of strings identifying the types of metadata objects to process.
- parameter startScanningAtLoad: Flag to know whether the view controller start scanning the codes when the view will appear.
:see: init(cancelButtonTitle:, coderReader:, startScanningAtLoad:)
*/
@available(iOS, deprecated, message = "Use init with builder instead.")
convenience public init(cancelButtonTitle: String, metadataObjectTypes: [String], startScanningAtLoad: Bool = true) {
let reader = QRCodeReader(metadataObjectTypes: metadataObjectTypes)
self.init(cancelButtonTitle: cancelButtonTitle, codeReader: reader, startScanningAtLoad: startScanningAtLoad)
}
/**
Initializes a view controller using a cancel button title and a code reader.
- parameter cancelButtonTitle: The title to use for the cancel button.
- parameter codeReader: The code reader object used to scan the bar code.
- parameter startScanningAtLoad: Flag to know whether the view controller start scanning the codes when the view will appear.
- parameter showSwitchCameraButton: Flag to display the switch camera button.
- parameter showTorchButton: Flag to display the toggle torch button. If the value is true and there is no torch the button will not be displayed.
- parameter showCancelButton: Flag to display the cancel button.
*/
@available(iOS, deprecated, message = "Use init with builder instead.")
public convenience init(cancelButtonTitle: String, codeReader reader: QRCodeReader, startScanningAtLoad startScan: Bool = true, showSwitchCameraButton showSwitch: Bool = true, showTorchButton showTorch: Bool = false, showCancelButton showCancel: Bool = true) {
self.init(builder: QRCodeViewControllerBuilder { builder in
builder.cancelButtonTitle = cancelButtonTitle
builder.reader = reader
builder.startScanningAtLoad = startScan
builder.showSwitchCameraButton = showSwitch
builder.showTorchButton = showTorch
builder.showCancelButton = showCancel
})
}
/**
Initializes a view controller using a builder.
- parameter builder: A QRCodeViewController builder object.
*/
required public init(builder: QRCodeViewControllerBuilder) {
startScanningAtLoad = builder.startScanningAtLoad
codeReader = builder.reader
showSwitchCameraButton = builder.showSwitchCameraButton
showTorchButton = builder.showTorchButton
showCancelButton = builder.showCancelButton
super.init(nibName: nil, bundle: nil)
view.backgroundColor = .blackColor()
codeReader.didFindCodeBlock = { [weak self] resultAsObject in
if let weakSelf = self {
weakSelf.completionBlock?(resultAsObject)
weakSelf.delegate?.reader(weakSelf, didScanResult: resultAsObject)
}
}
setupUIComponentsWithCancelButtonTitle(builder.cancelButtonTitle)
setupAutoLayoutConstraints()
cameraView.layer.insertSublayer(codeReader.previewLayer, atIndex: 0)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(orientationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil)
}
required public init?(coder aDecoder: NSCoder) {
codeReader = QRCodeReader(metadataObjectTypes: [])
startScanningAtLoad = false
showTorchButton = false
showSwitchCameraButton = false
showCancelButton = false
super.init(coder: aDecoder)
}
// MARK: - Responding to View Events
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return parentViewController?.supportedInterfaceOrientations() ?? .All
}
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if startScanningAtLoad {
startScanning()
}
}
override public func viewWillDisappear(animated: Bool) {
stopScanning()
super.viewWillDisappear(animated)
}
override public func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
codeReader.previewLayer.frame = view.bounds
}
// MARK: - Managing the Orientation
func orientationDidChange(notification: NSNotification) {
cameraView.setNeedsDisplay()
if let device = notification.object as? UIDevice where codeReader.previewLayer.connection.supportsVideoOrientation {
codeReader.previewLayer.connection.videoOrientation = QRCodeReader.videoOrientationFromDeviceOrientation(device.orientation, withSupportedOrientations: supportedInterfaceOrientations(), fallbackOrientation: codeReader.previewLayer.connection.videoOrientation)
}
}
// MARK: - Initializing the AV Components
private func setupUIComponentsWithCancelButtonTitle(cancelButtonTitle: String) {
cameraView.clipsToBounds = true
cameraView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(cameraView)
codeReader.previewLayer.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
if codeReader.previewLayer.connection.supportsVideoOrientation {
let orientation = UIDevice.currentDevice().orientation
codeReader.previewLayer.connection.videoOrientation = QRCodeReader.videoOrientationFromDeviceOrientation(orientation, withSupportedOrientations: supportedInterfaceOrientations())
}
if showSwitchCameraButton && codeReader.hasFrontDevice() {
let newSwitchCameraButton = SwitchCameraButton()
newSwitchCameraButton.translatesAutoresizingMaskIntoConstraints = false
newSwitchCameraButton.addTarget(self, action: #selector(switchCameraAction), forControlEvents: .TouchUpInside)
view.addSubview(newSwitchCameraButton)
switchCameraButton = newSwitchCameraButton
}
if showTorchButton && codeReader.isTorchAvailable() {
let newToggleTorchButton = ToggleTorchButton()
newToggleTorchButton.translatesAutoresizingMaskIntoConstraints = false
newToggleTorchButton.addTarget(self, action: #selector(toggleTorchAction), forControlEvents: .TouchUpInside)
view.addSubview(newToggleTorchButton)
toggleTorchButton = newToggleTorchButton
}
if showCancelButton {
let newCancelButton = UIButton()
newCancelButton.translatesAutoresizingMaskIntoConstraints = false
newCancelButton.setTitle(cancelButtonTitle, forState: .Normal)
newCancelButton.setTitleColor(.grayColor(), forState: .Highlighted)
newCancelButton.addTarget(self, action: #selector(cancelAction), forControlEvents: .TouchUpInside)
view.addSubview(newCancelButton)
cancelButton = newCancelButton
}
}
private func setupAutoLayoutConstraints() {
let views = ["cameraView": cameraView]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[cameraView]|", options: [], metrics: nil, views: views))
if let _cancelButton = cancelButton {
let cancelViews: [String: AnyObject] = ["cancelButton": _cancelButton, "cameraView": cameraView]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[cameraView][cancelButton(40)]|", options: [], metrics: nil, views: cancelViews))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[cancelButton]-|", options: [], metrics: nil, views: cancelViews))
} else {
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[cameraView]|", options: [], metrics: nil, views: views))
}
if let _switchCameraButton = switchCameraButton {
let switchViews: [String: AnyObject] = ["switchCameraButton": _switchCameraButton, "topGuide": topLayoutGuide]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[topGuide]-[switchCameraButton(50)]", options: [], metrics: nil, views: switchViews))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[switchCameraButton(70)]|", options: [], metrics: nil, views: switchViews))
}
if let _toggleTorchButton = toggleTorchButton {
let toggleViews: [String: AnyObject] = ["toggleTorchButton": _toggleTorchButton, "topGuide": topLayoutGuide]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[topGuide]-[toggleTorchButton(50)]", options: [], metrics: nil, views: toggleViews))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[toggleTorchButton(70)]", options: [], metrics: nil, views: toggleViews))
}
}
// MARK: - Controlling the Reader
/// Starts scanning the codes.
public func startScanning() {
codeReader.startScanning()
}
/// Stops scanning the codes.
public func stopScanning() {
codeReader.stopScanning()
}
// MARK: - Catching Button Events
func cancelAction(button: UIButton) {
codeReader.stopScanning()
if let _completionBlock = completionBlock {
_completionBlock(nil)
}
delegate?.readerDidCancel(self)
}
func switchCameraAction(button: SwitchCameraButton) {
codeReader.switchDeviceInput()
}
func toggleTorchAction(button: ToggleTorchButton) {
codeReader.toggleTorch()
}
}
/**
This protocol defines delegate methods for objects that implements the `QRCodeReaderDelegate`. The methods of the protocol allow the delegate to be notified when the reader did scan result and or when the user wants to stop to read some QRCodes.
*/
public protocol QRCodeReaderViewControllerDelegate: class {
/**
Tells the delegate that the reader did scan a code.
- parameter reader: A code reader object informing the delegate about the scan result.
- parameter result: The result of the scan
*/
func reader(reader: QRCodeReaderViewController, didScanResult result: QRCodeReaderResult)
/**
Tells the delegate that the user wants to stop scanning codes.
- parameter reader: A code reader object informing the delegate about the cancellation.
*/
func readerDidCancel(reader: QRCodeReaderViewController)
}

View File

@ -105,7 +105,7 @@ platform :ios, '8.0'
use_frameworks!
target 'TargetName' do
pod 'QRCodeReader.swift', '~> 7.0.1'
pod 'QRCodeReader.swift', '~> 7.1.0'
end
```
@ -137,7 +137,7 @@ $ brew install carthage
To integrate `QRCodeReader` into your Xcode project using Carthage, specify it in your `Cartfile` file:
```ogdl
github "yannickl/QRCodeReader.swift" >= 7.0.1
github "yannickl/QRCodeReader.swift" >= 7.1.0
```
#### Swift Package Manager
@ -151,7 +151,7 @@ let package = Package(
name: "YOUR_PROJECT_NAME",
targets: [],
dependencies: [
.Package(url: "https://github.com/yannickl/QRCodeReader.swift.git", versions: "7.0.1" ..< Version.max)
.Package(url: "https://github.com/yannickl/QRCodeReader.swift.git", versions: "7.1.0" ..< Version.max)
]
)
```

View File

@ -80,13 +80,20 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
// MARK: - Creating the Code Reade
/**
Initializes the code reader with the QRCode metadata type object.
*/
public convenience override init() {
self.init(metadataObjectTypes: [AVMetadataObjectTypeQRCode], captureDevicePosition: .back)
}
/**
Initializes the code reader with an array of metadata object types.
- parameter startingCaptureDevicePosition: The Camera to use on start of scanning
- parameter metadataObjectTypes: An array of strings identifying the types of metadata objects to process.
*/
public init(metadataObjectTypes types: [String] = [AVMetadataObjectTypeQRCode], captureDevicePosition: AVCaptureDevicePosition = .back) {
public init(metadataObjectTypes types: [String], captureDevicePosition: AVCaptureDevicePosition) {
metadataObjectTypes = types
super.init()