Showing
1 changed file
with
8 additions
and
11 deletions
| @@ -273,19 +273,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -273,19 +273,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 273 | device = nil | 273 | device = nil |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | - /// Toggle the flashlight between on and off | 276 | + /// Toggle the flashlight between on and off. |
| 277 | func toggleTorch(_ torch: AVCaptureDevice.TorchMode) throws { | 277 | func toggleTorch(_ torch: AVCaptureDevice.TorchMode) throws { |
| 278 | - if (device == nil) { | ||
| 279 | - throw MobileScannerError.torchWhenStopped | 278 | + if (device == nil || !device.hasTorch || !device.isTorchAvailable) { |
| 279 | + return | ||
| 280 | } | 280 | } |
| 281 | - if (device.hasTorch && device.isTorchAvailable) { | ||
| 282 | - do { | ||
| 283 | - try device.lockForConfiguration() | ||
| 284 | - device.torchMode = torch | ||
| 285 | - device.unlockForConfiguration() | ||
| 286 | - } catch { | ||
| 287 | - throw MobileScannerError.torchError(error) | ||
| 288 | - } | 281 | + |
| 282 | + if (device.torchMode != torch) { | ||
| 283 | + device.lockForConfiguration() | ||
| 284 | + device.torchMode = torch | ||
| 285 | + device.unlockForConfiguration() | ||
| 289 | } | 286 | } |
| 290 | } | 287 | } |
| 291 | 288 |
-
Please register or login to post a comment