Skip to content

Commit b7b6b4b

Browse files
authored
Merge pull request #101 from hyperoslo/fix/stop-capturing-on-deinit
Camera: stop capturing on deinit
2 parents 05f16d5 + 385767f commit b7b6b4b

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

BarcodeScanner.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "BarcodeScanner"
33
s.summary = "Simple and beautiful barcode scanner."
4-
s.version = "4.1.1"
4+
s.version = "4.1.2"
55
s.homepage = "https://github.com/hyperoslo/BarcodeScanner"
66
s.license = 'MIT'
77
s.author = { "Hyper Interaktiv AS" => "[email protected]" }

Example/BarcodeScannerExample/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: ../../
1010

1111
SPEC CHECKSUMS:
12-
BarcodeScanner: 91ac9634d249b4e59a5b57dff9264b691bc99ea6
12+
BarcodeScanner: e4b51b1c1c398bbf649e02da0d62c8c7a7de4c4f
1313

1414
PODFILE CHECKSUM: ea40d735f047f0ae7ae319d7a320a82facf3361f
1515

16-
COCOAPODS: 1.3.1
16+
COCOAPODS: 1.4.0

Sources/Controllers/BarcodeScannerViewController.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ open class BarcodeScannerViewController: UIViewController {
6060
private var locked = false
6161
/// Flag to check if layout constraints has been activated.
6262
private var constraintsActivated = false
63+
/// Flag to check if view controller is currently on screen
64+
private var isVisible = false
6365

6466
// MARK: - UI
6567

@@ -106,6 +108,12 @@ open class BarcodeScannerViewController: UIViewController {
106108
open override func viewWillAppear(_ animated: Bool) {
107109
super.viewWillAppear(animated)
108110
setupCameraConstraints()
111+
isVisible = true
112+
}
113+
114+
open override func viewWillDisappear(_ animated: Bool) {
115+
super.viewWillDisappear(animated)
116+
isVisible = false
109117
}
110118

111119
// MARK: - State handling
@@ -274,7 +282,6 @@ private extension BarcodeScannerViewController {
274282

275283
extension BarcodeScannerViewController: HeaderViewControllerDelegate {
276284
func headerViewControllerDidTapCloseButton(_ controller: HeaderViewController) {
277-
status = Status(state: .scanning)
278285
dismissalDelegate?.scannerDidDismiss(self)
279286
}
280287
}
@@ -304,7 +311,7 @@ extension BarcodeScannerViewController: CameraViewControllerDelegate {
304311

305312
func cameraViewController(_ controller: CameraViewController,
306313
didOutput metadataObjects: [AVMetadataObject]) {
307-
guard !locked else { return }
314+
guard !locked && isVisible else { return }
308315
guard !metadataObjects.isEmpty else { return }
309316

310317
guard

Sources/Controllers/CameraViewController.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public final class CameraViewController: UIViewController {
8181
// MARK: - Initialization
8282

8383
deinit {
84+
stopCapturing()
8485
NotificationCenter.default.removeObserver(self)
8586
}
8687

@@ -112,11 +113,6 @@ public final class CameraViewController: UIViewController {
112113
animateFocusView()
113114
}
114115

115-
public override func viewWillDisappear(_ animated: Bool) {
116-
super.viewWillDisappear(animated)
117-
captureSession.stopRunning()
118-
}
119-
120116
public override func viewWillTransition(to size: CGSize,
121117
with coordinator: UIViewControllerTransitionCoordinator) {
122118
super.viewWillTransition(to: size, with: coordinator)

0 commit comments

Comments
 (0)