Post

Replies

Boosts

Views

Activity

Reply to DataScannerViewController and torch
I followed the example on another site and configured the DeviceDiscoverySession and then activated the torch. This seems to have resolved the issue. func toggleTorch() { let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInUltraWideCamera, .builtInWideAngleCamera, .builtInTrueDepthCamera], mediaType: AVMediaType.video, position: cameraPosition) // adapted from [https://www.appsloveworld.com/swift/100/46/avcapturesession-freezes-when-torch-is-turned-on] to fix freezing issue when activating torch guard let device = deviceDiscoverySession.devices.first else {return} if device.hasTorch && device.isTorchAvailable { do { try device.lockForConfiguration() if torchIsOn { try device.setTorchModeOn(level: 1.0) // adjust torch intensity here } else { device.torchMode = .off } device.unlockForConfiguration() } catch { print("Torch could not be used") } } else { print("Torch is not available") } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23
Reply to DataScannerViewController and torch
I ran into the same issue today when testing on an iPhone. The interesting thing is that when I tested on an iPad the torch came on and off without freezing the DataScannerViewController. They both run the same SwiftUI code with no differences in how the sheet is handled in iOS or iPad OS. I’ll do some more testing tomorrow and see if I can reproduce in a sample app.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23