Flutter MacOS MethodChannel 与 AppDelegate 的通信

Flutter MacOS MethodChannel Communication to AppDelegate

如何在 MacOS Flutter 应用程序的 Swift 端访问 AppDelegate 中的 FlutterBinaryMessenger?在我找到的所有示例中,AppDelegate 只是一个占位符。您需要获取 FlutterBinaryMessenger 以实例化 FlutterMethodChannel 以实际与 Dart 端通信。

在当前的 macOS 模板中,FlutterViewController(可让您通过 .engine.binaryMessenger 获取 Messenger)属于 window,而非应用程序。如果您想从 AppDelegate 访问它,您需要在 AppDelegateMainFlutterWindow 之间建立连接。