admin管理员组文章数量:1291037
I am facing an issue in iOS 18 that works fine in iOS 17 and earlier.
This happens when you set the project to use Swift 6.
The app has the Privacy - Camera Usage Description key in the Info.plist.
It is a wrapper that implements UIViewControllerRepresentable to create the UIViewController. This wrapper is within a view that gets pushed when the user presses a button (see snippet code below).
Sometimes, I get a popup asking for permission to access the camera, and the app crashes immediately. Other times, I don’t see the popup, and the app crashes right away.
I tried adding Task { @MainActor }
within the requestAccess closure, but it did not resolve the issue. It does not matter the code within the closure; it crashes even if the closure is empty.
The crash trace shows _dispatch_assert_queue_fail
(see the attached image).
Has anyone else experienced this issue? Any insights would be greatly appreciated.
The following code will crash if run as is. Please add the Privacy - Camera Usage Description
key in the Info.plist to prevent this issue.
import SwiftUI
import AVFoundation
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
ViewControllerWrapper()
}
}
}
struct ViewControllerWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> ViewController {
ViewController()
}
func updateUIViewController(_ viewController: ViewController, context: Context) {}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
AVCaptureDevice.requestAccess(for: .video) { _ in
}
}
}
Error trace:
I am facing an issue in iOS 18 that works fine in iOS 17 and earlier.
This happens when you set the project to use Swift 6.
The app has the Privacy - Camera Usage Description key in the Info.plist.
It is a wrapper that implements UIViewControllerRepresentable to create the UIViewController. This wrapper is within a view that gets pushed when the user presses a button (see snippet code below).
Sometimes, I get a popup asking for permission to access the camera, and the app crashes immediately. Other times, I don’t see the popup, and the app crashes right away.
I tried adding Task { @MainActor }
within the requestAccess closure, but it did not resolve the issue. It does not matter the code within the closure; it crashes even if the closure is empty.
The crash trace shows _dispatch_assert_queue_fail
(see the attached image).
Has anyone else experienced this issue? Any insights would be greatly appreciated.
The following code will crash if run as is. Please add the Privacy - Camera Usage Description
key in the Info.plist to prevent this issue.
import SwiftUI
import AVFoundation
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
ViewControllerWrapper()
}
}
}
struct ViewControllerWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> ViewController {
ViewController()
}
func updateUIViewController(_ viewController: ViewController, context: Context) {}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
AVCaptureDevice.requestAccess(for: .video) { _ in
}
}
}
Error trace:
Share Improve this question edited Feb 14 at 9:31 Luciano Perez asked Feb 13 at 19:55 Luciano PerezLuciano Perez 1012 silver badges12 bronze badges 01 Answer
Reset to default 1I found a potential fix for this issue: The async method needs to be called instead of the one with the completion handler.
Task {
let accessIsGranted = await AVCaptureDevice.requestAccess(for: .video)
}
本文标签: video captureCrash in AVCaptureDevicerequestAccess in iOS 18 with swift 6Stack Overflow
版权声明:本文标题:video capture - Crash in AVCaptureDevice.requestAccess in iOS 18 with swift 6 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741507769a2382424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论