FlutterMethodChannel

@interface FlutterMethodChannel : NSObject

A channel for communicating with the Flutter side using invocation of asynchronous methods.

  • Creates a FlutterMethodChannel with the specified name and binary messenger.

    The channel name logically identifies the channel; identically named channels interfere with each other’s communication.

    The binary messenger is a facility for sending raw, binary messages to the Flutter side. This protocol is implemented by FlutterViewController.

    The channel uses FlutterStandardMethodCodec to encode and decode method calls and result envelopes.

    Declaration

    Objective-C

    + (nonnull instancetype)
    methodChannelWithName:(nonnull NSString *)name
          binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger;
  • Creates a FlutterMethodChannel with the specified name, binary messenger, and method codec.

    The channel name logically identifies the channel; identically named channels interfere with each other’s communication.

    The binary messenger is a facility for sending raw, binary messages to the Flutter side. This protocol is implemented by FlutterViewController.

    Declaration

    Objective-C

    + (nonnull instancetype)
    methodChannelWithName:(nonnull NSString *)name
          binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger
                    codec:(nonnull NSObject<FlutterMethodCodec> *)codec;
  • Initializes a FlutterMethodChannel with the specified name, binary messenger, and method codec.

    The channel name logically identifies the channel; identically named channels interfere with each other’s communication.

    The binary messenger is a facility for sending raw, binary messages to the Flutter side. This protocol is implemented by FlutterViewController.

    Declaration

    Objective-C

    - (nonnull instancetype)
       initWithName:(nonnull NSString *)name
    binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger
              codec:(nonnull NSObject<FlutterMethodCodec> *)codec;
  • Invokes the specified Flutter method with the specified arguments, expecting no results.

    Declaration

    Objective-C

    - (void)invokeMethod:(nonnull NSString *)method
               arguments:(id _Nullable)arguments;
  • Invokes the specified Flutter method with the specified arguments, expecting an asynchronous result.

    Declaration

    Objective-C

    - (void)invokeMethod:(nonnull NSString *)method
               arguments:(id _Nullable)arguments
                  result:(FlutterResult _Nullable)callback;
  • Registers a handler for method calls from the Flutter side.

    Replaces any existing handler. Use a nil handler for unregistering the existing handler.

    Declaration

    Objective-C

    - (void)setMethodCallHandler:(FlutterMethodCallHandler _Nullable)handler;