I’m developing a Flutter application and a non-UI (MacOS/iOS) File Provider Extension. The extension runs in a separate process and I need the Flutter code to communicate with the extension.
Ideally I would have one BasicMessageChannel
in the flutter app and one FlutterBinaryMessenger
in the extension.
So far, I have managed to have the above classes to communicate but only between the flutter isolate and the hosting app’s Swift code which contains the AppDelegate
. The code is similar to this.
Having the FlutterBinaryMessenger
in the extension code is harder because the FlutterEngine
does not run there by default. I tried to create one with this code:
let bundle = Bundle()
let project = FlutterDartProject(precompiledDartBundle: bundle)
let flutterEngine = FlutterEngine(
name: "Extension flutter engine",
project: project)
let success = flutterEngine.run(withEntrypoint: nil)
NSLog("Success starting flutter engine: success")
Unfortunately the flutterEngine.run(withEntrypoint: nil)
command returns false
and I’m not sure how to progress from there.
The other problem is that even if I do get the engine to start, I’m not even sure whether Inter Process Communication is supposed to work with these Flutter message channels or whether it’s just to support communication with the Flutter isolate and its hosting code that both run in the same process.
I can think of a workaround, which would be to use Flutter Messenger for the communication between Flutter and the hosting app and then use XPC for communication between the hosting app and the extension. Though would like to avoid that if possible.
3