I can attest that AVCaptureDevice.requestAccess suffered from this same problem, i.e. crashing with a thread/queue violation when built under Swift 6.
Original code:
AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { granted in
if (granted)
{
DispatchQueue.main.async { [weak self] in
// do something
}
}
})
Modified code:
Task {
let granted = await AVCaptureDevice.requestAccess(for: .video)
if (granted) {
Task { @MainActor in
// do something
}
}
}
This code pops a permission dialog for using the camera, and as soon as the Allow button is clicked the app would crash.
Topic:
Programming Languages
SubTopic:
Swift
Tags: