This is broken again in iOS17 (up through 17.0.2) as of 9/22/23. Looking for solutions but nothing resolves the issue yet.
Post
Replies
Boosts
Views
Activity
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")
}
}
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.
I’m experiencing something that might be related.
My first tab has a VideoPlayer and another view in an HStack. The video comes up, shows controls, and responds to all taps.
Tab two is a full screen version of that same VideoPlayer view. The first frame of the video comes up but I never see controls or any ability to start the video.
I’ve tried making different views wondering if there is a limitation of having only one of the VideoPlayers or what but I can’t find a way to get tab 2 to work.
I have latest XCode and iOS as of 10/17/20.