add missing DispatchQueue.main switch for scale & torch on iOS
Showing
1 changed file
with
11 additions
and
2 deletions
| @@ -216,9 +216,12 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -216,9 +216,12 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 216 | backgroundQueue.async { | 216 | backgroundQueue.async { |
| 217 | self.captureSession.startRunning() | 217 | self.captureSession.startRunning() |
| 218 | 218 | ||
| 219 | - // Turn on the flashlight if requested, | ||
| 220 | - // but after the capture session started. | 219 | + // After the capture session started, turn on the torch (if requested) |
| 220 | + // and reset the zoom scale back to the default. | ||
| 221 | + // Ensure that these adjustments are done on the main DispatchQueue, | ||
| 222 | + // as they interact with the hardware camera. | ||
| 221 | if (torch) { | 223 | if (torch) { |
| 224 | + DispatchQueue.main.async { | ||
| 222 | do { | 225 | do { |
| 223 | try self.toggleTorch(.on) | 226 | try self.toggleTorch(.on) |
| 224 | } catch { | 227 | } catch { |
| @@ -226,15 +229,21 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -226,15 +229,21 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 226 | // continue with the capture session anyway. | 229 | // continue with the capture session anyway. |
| 227 | } | 230 | } |
| 228 | } | 231 | } |
| 232 | + } | ||
| 229 | 233 | ||
| 234 | + DispatchQueue.main.async { | ||
| 230 | do { | 235 | do { |
| 231 | try self.resetScale() | 236 | try self.resetScale() |
| 232 | } catch { | 237 | } catch { |
| 233 | // If the zoom scale could not be reset, | 238 | // If the zoom scale could not be reset, |
| 234 | // continue with the capture session anyway. | 239 | // continue with the capture session anyway. |
| 235 | } | 240 | } |
| 241 | + } | ||
| 236 | 242 | ||
| 237 | if let device = self.device { | 243 | if let device = self.device { |
| 244 | + // When querying the dimensions of the camera, | ||
| 245 | + // stay on the background thread, | ||
| 246 | + // as this does not change the configuration of the hardware camera. | ||
| 238 | let dimensions = CMVideoFormatDescriptionGetDimensions( | 247 | let dimensions = CMVideoFormatDescriptionGetDimensions( |
| 239 | device.activeFormat.formatDescription) | 248 | device.activeFormat.formatDescription) |
| 240 | let hasTorch = device.hasTorch | 249 | let hasTorch = device.hasTorch |
-
Please register or login to post a comment