[ADD] stopScanningWhenCodeIsFound property #41

This commit is contained in:
Yannick Loriot 2016-01-24 15:36:19 +01:00
parent fe54455e66
commit cc6f25bb37
2 changed files with 11 additions and 3 deletions

View File

@ -4,6 +4,7 @@
Released on 2016-01-24.
- [REFACTORING] Rename `completionBlock` of `QRCodeReader` to `codeDidFoundBlock`.
- [ADD] `stopScanningWhenCodeIsFound` flag to stop the scanner when a code is found.
## [Version 5.3.1](https://github.com/yannickl/QRCodeReader.swift/releases/tag/5.3.1)
Released on 2016-01-12.

View File

@ -67,7 +67,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
// MARK: - Managing the Code Discovery
//public var stopScanningWhenCodeIsFound: Bool = true
/// Flag to know whether the scanner should stop scanning when a code is found.
public var stopScanningWhenCodeIsFound: Bool = true
/// Block is executing when a QRCode or when the user did stopped the scan.
public var codeDidFoundBlock: (QRCodeReaderResult -> Void)?
@ -126,7 +127,11 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
// MARK: - Controlling Reader
/// Starts scanning the codes.
/**
Starts scanning the codes.
*Notes: if `stopScanningWhenCodeIsFound` is sets to true (default behaviour), each time the scanner found a code it calls the `stopScanning` method.*
*/
public func startScanning() {
if !session.running {
session.startRunning()
@ -271,7 +276,9 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
for current in metadataObjects {
if let _readableCodeObject = current as? AVMetadataMachineReadableCodeObject {
if metadataObjectTypes.contains(_readableCodeObject.type) {
if stopScanningWhenCodeIsFound {
stopScanning()
}
let scannedResult = QRCodeReaderResult(value: _readableCodeObject.stringValue, metadataType:_readableCodeObject.type)