Showing
1 changed file
with
9 additions
and
3 deletions
| @@ -286,12 +286,18 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -286,12 +286,18 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 286 | device = nil | 286 | device = nil |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | - /// Toggle the flashlight between on and off. | 289 | + /// Set the torch mode. |
| 290 | + /// | ||
| 291 | + /// This method should be called on the main DispatchQueue. | ||
| 290 | func toggleTorch(_ torch: AVCaptureDevice.TorchMode) throws { | 292 | func toggleTorch(_ torch: AVCaptureDevice.TorchMode) throws { |
| 291 | - if (device == nil || !device.hasTorch || !device.isTorchAvailable) { | 293 | + guard let device = self.device else { |
| 292 | return | 294 | return |
| 293 | } | 295 | } |
| 294 | - | 296 | + |
| 297 | + if (!device.hasTorch || !device.isTorchAvailable || !device.isTorchModeSupported(torch)) { | ||
| 298 | + return | ||
| 299 | + } | ||
| 300 | + | ||
| 295 | if (device.torchMode != torch) { | 301 | if (device.torchMode != torch) { |
| 296 | try device.lockForConfiguration() | 302 | try device.lockForConfiguration() |
| 297 | device.torchMode = torch | 303 | device.torchMode = torch |
-
Please register or login to post a comment