I’ve a working Flutter Undertaking.
Then I’ve to hook up with a printer. This printer firm offered an API/SDK for me to eat. The code is written in a .h and .a file.
That is simply an iOS connection, no want for Android.
To check a easy connection, these are what I did:
- I created a folder inside ios/Runner mission and named it “PrinterCheck”, this folder accommodates the .a and .h recordsdata they offered.
- I modified my AppDelegate
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController;
let methodChannel = FlutterMethodChannel(title: "PrinterCheck", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler{
(name: FlutterMethodCall, consequence: FlutterResult) -> Void in
if("printHello" == name.technique){
//TODO: execute a easy print to ensure it connects to the recordsdata
consequence(true);
} else {
consequence(FlutterMethodNotImplemented)
}
}
GeneratedPluginRegistrant.register(with: self)
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
}
}
- I created a .m file with a easy printHello technique returning a false bool worth simply to check a connection. I put this .m file in the identical folder the place the .h and .a are situated.
- (BOOL)printHello:(NSString *)printValue {
return false;
}
- And in Dart, I invoke the strategy
const platform = const MethodChannel('PrinterCheck');
var consequence = await platform.invokeMethod('printHello', {"printValue": "check"});
I need to understand how I can invoke from the TODO line the printHello from .m file. The consequence(true) is working as is however I need to print false from .m file as a substitute. Thanks.