Hi guys,
I’m experimenting with MOE and Flutter together in order to have a real common source base for both Android and iOS.
I’ve got most of it working but I’m stuck on a minor(?) problem with the binding.
To give you a bit of background, what I did is the following.
- In Android Studio I’ve installed both MOE and Flutter plugin.
- I’ve created a new MOE project with 3 modules, android, common and ios.
- I’ve added support for CocoaPod to the ios module.
- I’ve created a new flutter module following https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
- I’ve created a binding for the Flutter framework
- I’ve adapted the Objective-C code from the link above to the binding code in MOE.
- I’ve disabled the storyboard in xcode and forced the AppDelegate to load the FlutterViewController
And, it works! It was straightforward and it’s working really well, I’m really happy with this.
The next step is to call native code from Flutter, and here I’m stuck.
I’m following https://flutter.io/docs/development/platform-integration/platform-channels and at some point they call this:
FlutterMethodChannel* batteryChannel = [FlutterMethodChannel
methodChannelWithName:@"samples.flutter.io/battery"
binaryMessenger:controller];
[batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
// TODO
}];
The moeNatJGen gradlew task generated FlutterMethodChannel but not the setMethodCallHandler method.
I looked in the log and there are exactly 5 skipped methods in all the framework, including this one (how lucky! )
This is the log:
**Skipping:** setMessageHandler: in FlutterBasicMessageChannel (Objective-C Instance Method) reason: *unhadled callback at arg(handler@0) type [^(void)(@id, ^(void)(@id))]*
**Skipping:** userNotificationCenter:willPresentNotification:withCompletionHandler: in FlutterPluginAppLifeCycleDelegate (Objective-C Instance Method) reason: *bad argument(1) type [object type 'UNNotification' is not processed]*
**Skipping:** setMethodCallHandler: in FlutterMethodChannel (Objective-C Instance Method) reason: *unhadled callback at arg(handler@0) type [^(void)(FlutterMethodCall*, ^(void)(@id))]*
**Skipping:** setMessageHandlerOnChannel:binaryMessageHandler: in FlutterBinaryMessenger (Objective-C Instance Method) reason: *unhadled callback at arg(handler@1) type [^(void)(NSData*, ^(void)(NSData*))]*
**Skipping:** userNotificationCenter:willPresentNotification:withCompletionHandler: in FlutterPlugin (Objective-C Instance Method) reason: *bad argument(1) type [object type 'UNNotification' is not processed]*
I was thinking that maybe I can fix the binding code manually, it’s not the first method I bind myself, but in this particular case I don’t know how to proceed.
The relevant parts from the header file (FlutterChannels.h) are these:
typedef void (^FlutterResult)(id _Nullable result);
typedef void (^FlutterMethodCallHandler)(FlutterMethodCall* call, FlutterResult result);
- (void)setMethodCallHandler:(FlutterMethodCallHandler _Nullable)handler;
Any idea how can I bind the setMethodCallHandler method? I don’t mind about the other methods for now. This is really blocking me on the last step of this project.
Thanks for the help!