Skip to content

Commit

Permalink
Camera: stop capturing in deinit
Browse files Browse the repository at this point in the history
  • Loading branch information
vadymmarkov committed Feb 5, 2018
1 parent 05f16d5 commit 26e9f30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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 26e9f30

Please sign in to comment.