Navaron Bracke

check if torch mode is supported on MacOS

@@ -320,7 +320,11 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, @@ -320,7 +320,11 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
320 320
321 // TODO: this method should be removed when iOS and MacOS share their implementation. 321 // TODO: this method should be removed when iOS and MacOS share their implementation.
322 private func toggleTorchInternal(_ torch: AVCaptureDevice.TorchMode) throws { 322 private func toggleTorchInternal(_ torch: AVCaptureDevice.TorchMode) throws {
323 - if (device == nil || !device.hasTorch) { 323 + guard let device = self.device else {
  324 + return
  325 + }
  326 +
  327 + if (!device.hasTorch || !device.isTorchModeSupported(torch)) {
324 return 328 return
325 } 329 }
326 330
@@ -337,7 +341,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, @@ -337,7 +341,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
337 } 341 }
338 } 342 }
339 343
340 - func toggleTorch(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { 344 + private func toggleTorch(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
341 let requestedTorchMode: AVCaptureDevice.TorchMode = call.arguments as! Int == 1 ? .on : .off 345 let requestedTorchMode: AVCaptureDevice.TorchMode = call.arguments as! Int == 1 ? .on : .off
342 346
343 do { 347 do {