I want to add the Flutter platform channel in an iOS share extension ( Is this even possible?
In the main app's AppDelegate I would simply use something like this:
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel(name: "<channelName>",
binaryMessenger: controller.binaryMessenger)
In the FlutterMethodChannel initialization, a binaryMessenger of the type FlutterBinaryMessenger is required.
In the ShareViewController I tried to create a class of the type FlutterAppDelegate, and create there FlutterViewController But turns out the controller is null.
@objc class ExtDelegate: FlutterAppDelegate {
func invokeMethod(
) -> Bool {
let controller = (window.rootViewController as! FlutterViewController)
let methodChannel =
FlutterMethodChannel(name: "task-identifier", binaryMessenger: controller.binaryMessenger)
methodChannel.invokeMethod("fetchImage", arguments: "Arg-s")
return true
}
}
Any ideas on how to realize this?