Skip to content

Commit

Permalink
Merge pull request #101 from hyperoslo/fix/stop-capturing-on-deinit
Browse files Browse the repository at this point in the history
Camera: stop capturing on deinit
  • Loading branch information
vadymmarkov authored Feb 5, 2018
2 parents 05f16d5 + 385767f commit b7b6b4b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion BarcodeScanner.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
Expand Down
4 changes: 2 additions & 2 deletions Example/BarcodeScannerExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: ../../

SPEC CHECKSUMS:
BarcodeScanner: 91ac9634d249b4e59a5b57dff9264b691bc99ea6
BarcodeScanner: e4b51b1c1c398bbf649e02da0d62c8c7a7de4c4f

PODFILE CHECKSUM: ea40d735f047f0ae7ae319d7a320a82facf3361f

COCOAPODS: 1.3.1
COCOAPODS: 1.4.0
11 changes: 9 additions & 2 deletions Sources/Controllers/BarcodeScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -274,7 +282,6 @@ private extension BarcodeScannerViewController {

extension BarcodeScannerViewController: HeaderViewControllerDelegate {
func headerViewControllerDidTapCloseButton(_ controller: HeaderViewController) {
status = Status(state: .scanning)
dismissalDelegate?.scannerDidDismiss(self)
}
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Sources/Controllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class CameraViewController: UIViewController {
// MARK: - Initialization

deinit {
stopCapturing()
NotificationCenter.default.removeObserver(self)
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b7b6b4b

Please sign in to comment.