Skip to content

Commit e8bfe5f

Browse files
Merge pull request juliansteenbakker#1401 from navaronbracke/fix_ios_remove_observer_crash
Fix: remove observer when device is nil
2 parents 36a145f + 814f5c9 commit e8bfe5f

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 6.0.10
2+
* [Apple] Fixed a crash when stopping the camera when the camera device is nil.
3+
14
## 6.0.9
25
Fixed onDetect not working when a `MobileScannerController` is provided.
36

ios/Classes/MobileScanner.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
324324
}
325325

326326
private func releaseCamera() {
327-
328327
guard let captureSession = captureSession else {
329328
return
330329
}
330+
331+
guard let device = device else {
332+
return
333+
}
331334

332335
captureSession.stopRunning()
333336
for input in captureSession.inputs {
@@ -341,7 +344,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
341344
device.removeObserver(self, forKeyPath: #keyPath(AVCaptureDevice.torchMode))
342345
device.removeObserver(self, forKeyPath: #keyPath(AVCaptureDevice.videoZoomFactor))
343346
self.captureSession = nil
344-
device = nil
347+
self.device = nil
345348
}
346349

347350
private func releaseTexture() {

macos/mobile_scanner/Sources/mobile_scanner/MobileScannerPlugin.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
481481
return
482482
}
483483

484+
guard let device = device else {
485+
return
486+
}
487+
484488
captureSession.stopRunning()
485489
for input in captureSession.inputs {
486490
captureSession.removeInput(input)
@@ -492,7 +496,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
492496

493497
latestBuffer = nil
494498
self.captureSession = nil
495-
device = nil
499+
self.device = nil
496500
}
497501

498502
private func releaseTexture() {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: mobile_scanner
22
description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
3-
version: 6.0.9
3+
version: 6.0.10
44
repository: https://github.com/juliansteenbakker/mobile_scanner
55

66
screenshots:

0 commit comments

Comments
 (0)