I have a working Flutter Project.
Then I have to connect to a printer. This printer company provided an API/SDK for me to consume. The code is written in a .h and .a file.
This is just an iOS connection, no need for Android.
To test a simple connection, these are what I did:
- I created a folder inside ios/Runner project and named it "PrinterCheck", this folder contains the .a and .h files they provided.
- I modified my AppDelegate
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController;
let methodChannel = FlutterMethodChannel(name: "PrinterCheck", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler{
(call: FlutterMethodCall, result: FlutterResult) -> Void in
if("printHello" == call.method){
//TODO: execute a simple print to make sure it connects to the files
result(true);
} else {
result(FlutterMethodNotImplemented)
}
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
- I created a .m file with a simple printHello method returning a false bool value just to test a connection. I put this .m file in the same folder where the .h and .a are located.
- (BOOL)printHello:(NSString *)printValue {
return false;
}
- And in Dart, I invoke the method
const platform = const MethodChannel('PrinterCheck');
var result = await platform.invokeMethod('printHello', {"printValue": "test"});
I want to know how I can invoke from the TODO line the printHello from .m file. The result(true) is working as is but I want to print false from .m file instead. Thank you.