Вот упрощенная версия моего кода: < /p>
Код: Выделить всё
private func initialize(
_ call: FlutterMethodCall,
result: @escaping FlutterResult
) {
getNavigationControllerLegacy(call: call, result: result) { methodCall, flutterResult, navigation in
guard let nav = navigation else {
flutterResult(FlutterError(code: "NO_NAV", message: "Navigation controller not found", details: nil))
return
}
let liveness = Liveness(methodCall, result: flutterResult)
liveness.viewController = nav
liveness.execute()
}
}
private func getNavigationControllerLegacy(
call: FlutterMethodCall,
result: @escaping FlutterResult,
completion: @escaping @Sendable (FlutterMethodCall, @escaping FlutterResult, UINavigationController?) -> Void
) {
DispatchQueue.main.async {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first,
let rootViewController = window.rootViewController else {
completion(call, result, nil)
return
}
var navigationController: UINavigationController?
if let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }),
let rootViewController = window.rootViewController {
if let nav = rootViewController as? UINavigationController {
navigationController = nav
} else if let nav = rootViewController.navigationController {
navigationController = nav
}
}
completion(call, result, navigationController)
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... data-races