9.8 C
Tuesday, November 21, 2023

swift – Flutter to iOS – Use FlutterMethodChannel to iOS recordsdata in Goal C

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:

  1. I created a folder inside ios/Runner mission and named it “PrinterCheck”, this folder accommodates the .a and .h recordsdata they offered.
  2. I modified my AppDelegate
import Flutter

@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)
      (name: FlutterMethodCall, consequence: FlutterResult) -> Void in
        if("printHello" == name.technique){
          //TODO: execute a easy print to ensure it connects to the recordsdata
        } else {

    GeneratedPluginRegistrant.register(with: self)
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  1. 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;
  1. 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.

Latest news
Related news


Please enter your comment!
Please enter your name here