Showing
1 changed file
with
8 additions
and
2 deletions
| @@ -286,9 +286,15 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -286,9 +286,15 @@ 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 { |
| 294 | + return | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + if (!device.hasTorch || !device.isTorchAvailable || !device.isTorchModeSupported(torch)) { | ||
| 292 | return | 298 | return |
| 293 | } | 299 | } |
| 294 | 300 |
-
Please register or login to post a comment