From 26e9f301682d08a37aa97ea96daf1d2b13cf33bd Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 5 Feb 2018 22:22:28 +0100 Subject: [PATCH 1/2] Camera: stop capturing in deinit --- Example/BarcodeScannerExample/Podfile.lock | 4 ++-- .../Controllers/BarcodeScannerViewController.swift | 11 +++++++++-- Sources/Controllers/CameraViewController.swift | 6 +----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Example/BarcodeScannerExample/Podfile.lock b/Example/BarcodeScannerExample/Podfile.lock index 4a3d3af..73c751d 100644 --- a/Example/BarcodeScannerExample/Podfile.lock +++ b/Example/BarcodeScannerExample/Podfile.lock @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: ../../ SPEC CHECKSUMS: - BarcodeScanner: 91ac9634d249b4e59a5b57dff9264b691bc99ea6 + BarcodeScanner: e4b51b1c1c398bbf649e02da0d62c8c7a7de4c4f PODFILE CHECKSUM: ea40d735f047f0ae7ae319d7a320a82facf3361f -COCOAPODS: 1.3.1 +COCOAPODS: 1.4.0 diff --git a/Sources/Controllers/BarcodeScannerViewController.swift b/Sources/Controllers/BarcodeScannerViewController.swift index eb835dc..417a4e3 100644 --- a/Sources/Controllers/BarcodeScannerViewController.swift +++ b/Sources/Controllers/BarcodeScannerViewController.swift @@ -60,6 +60,8 @@ open class BarcodeScannerViewController: UIViewController { private var locked = false /// Flag to check if layout constraints has been activated. private var constraintsActivated = false + /// Flag to check if view controller is currently on screen + private var isVisible = false // MARK: - UI @@ -106,6 +108,12 @@ open class BarcodeScannerViewController: UIViewController { open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) setupCameraConstraints() + isVisible = true + } + + open override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + isVisible = false } // MARK: - State handling @@ -274,7 +282,6 @@ private extension BarcodeScannerViewController { extension BarcodeScannerViewController: HeaderViewControllerDelegate { func headerViewControllerDidTapCloseButton(_ controller: HeaderViewController) { - status = Status(state: .scanning) dismissalDelegate?.scannerDidDismiss(self) } } @@ -304,7 +311,7 @@ extension BarcodeScannerViewController: CameraViewControllerDelegate { func cameraViewController(_ controller: CameraViewController, didOutput metadataObjects: [AVMetadataObject]) { - guard !locked else { return } + guard !locked && isVisible else { return } guard !metadataObjects.isEmpty else { return } guard diff --git a/Sources/Controllers/CameraViewController.swift b/Sources/Controllers/CameraViewController.swift index b184d2e..c7bea10 100644 --- a/Sources/Controllers/CameraViewController.swift +++ b/Sources/Controllers/CameraViewController.swift @@ -81,6 +81,7 @@ public final class CameraViewController: UIViewController { // MARK: - Initialization deinit { + stopCapturing() NotificationCenter.default.removeObserver(self) } @@ -112,11 +113,6 @@ public final class CameraViewController: UIViewController { animateFocusView() } - public override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - captureSession.stopRunning() - } - public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) From 385767f0908f89391922664baa465c141be008bc Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 5 Feb 2018 22:23:24 +0100 Subject: [PATCH 2/2] Update podspec --- BarcodeScanner.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BarcodeScanner.podspec b/BarcodeScanner.podspec index 14eb778..dbdd097 100644 --- a/BarcodeScanner.podspec +++ b/BarcodeScanner.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "BarcodeScanner" s.summary = "Simple and beautiful barcode scanner." - s.version = "4.1.1" + s.version = "4.1.2" s.homepage = "https://github.com/hyperoslo/BarcodeScanner" s.license = 'MIT' s.author = { "Hyper Interaktiv AS" => "ios@hyper.no" }