flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

How to register method channel listener in native side

Open LangInteger opened this issue 3 years ago • 5 comments

Hi, I want to call the method channel on iOS side in the background job, but I got the following error when I tried to do so:

flutter: Exception happen: MissingPluginException(No implementation found for method echo on channel com.foo.bar)

Declaring the method channel in AppDelegate.swift:

      //=======================================================================================
      //====================  iOS native side custom method channel callee  ===================
      //=======================================================================================
      print("setup channel")
      let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
      let channel = FlutterMethodChannel(name: "com.foo.bar", binaryMessenger: controller.binaryMessenger)
      channel.setMethodCallHandler({
        (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
          if (call.method == "echo") {
              result(call.arguments as? String);
          } else {
              result("Not Implemented")
          }
      })

Calling method channel from callbackDispatcher with:

  final channel = MethodChannel("com.foo.bar");
  await channel.invokeMethod<String>("echo", "${DateTime.now()}");

Any suggestions on this situation?

LangInteger avatar Jul 19 '22 03:07 LangInteger

Hi, I want to call the method channel on iOS side in the background job, but I got the following error when I tried to do so:

flutter: Exception happen: MissingPluginException(No implementation found for method echo on channel com.foo.bar)

Declaring the method channel in AppDelegate.swift:

      //=======================================================================================
      //====================  iOS native side custom method channel callee  ===================
      //=======================================================================================
      print("setup channel")
      let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
      let channel = FlutterMethodChannel(name: "com.foo.bar", binaryMessenger: controller.binaryMessenger)
      channel.setMethodCallHandler({
        (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
          if (call.method == "echo") {
              result(call.arguments as? String);
          } else {
              result("Not Implemented")
          }
      })

Calling method channel from callbackDispatcher with:

  final channel = MethodChannel("com.foo.bar");
  await channel.invokeMethod<String>("echo", "${DateTime.now()}");

Any suggestions on this situation?

Did you solve the problem?

kitoheedong avatar Sep 23 '22 04:09 kitoheedong

@heedongrichrich not yet.

LangInteger avatar Sep 23 '22 05:09 LangInteger

Same issue facing here @LangInteger @heedongrichrich

Nitingadhiya avatar Sep 23 '22 08:09 Nitingadhiya

@Nitingadhiya Man, I just decided to implement by myself hahaha~ It's a bit way better to implement background dispatch since there is no "one size fits all strategies" at this moment.

kitoheedong avatar Sep 23 '22 14:09 kitoheedong

any update?

Cmk427 avatar Apr 30 '24 00:04 Cmk427