FlutterMethodChannel
Objective-C
@interface FlutterMethodChannel : NSObject
Swift
class FlutterMethodChannel : NSObject
A channel for communicating with the Flutter side using invocation of asynchronous methods.
-
Creates a
FlutterMethodChannelwith 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
FlutterEngineandFlutterViewController.The channel uses
FlutterStandardMethodCodecto encode and decode method calls and result envelopes.Declaration
Objective-C
+ (nonnull instancetype) methodChannelWithName:(nonnull NSString *)name binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger;Swift
convenience init(name: String, binaryMessenger messenger: FlutterBinaryMessenger)Parameters
nameThe channel name.
messengerThe binary messenger.
-
Creates a
FlutterMethodChannelwith 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
FlutterEngineandFlutterViewController.Declaration
Objective-C
+ (nonnull instancetype) methodChannelWithName:(nonnull NSString *)name binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger codec:(nonnull NSObject<FlutterMethodCodec> *)codec;Parameters
nameThe channel name.
messengerThe binary messenger.
codecThe method codec.
-
Initializes a
FlutterMethodChannelwith 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
FlutterEngineandFlutterViewController.Declaration
Objective-C
- (nonnull instancetype) initWithName:(nonnull NSString *)name binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger codec:(nonnull NSObject<FlutterMethodCodec> *)codec;Swift
init(name: String, binaryMessenger messenger: FlutterBinaryMessenger, codec: FlutterMethodCodec & NSObjectProtocol)Parameters
nameThe channel name.
messengerThe binary messenger.
codecThe method codec.
-
Initializes a
FlutterMethodChannelwith the specified name, binary messenger, method codec, and task queue.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
FlutterEngineandFlutterViewController.Declaration
Objective-C
- (nonnull instancetype) initWithName:(nonnull NSString *)name binaryMessenger:(nonnull NSObject<FlutterBinaryMessenger> *)messenger codec:(nonnull NSObject<FlutterMethodCodec> *)codec taskQueue:(NSObject<FlutterTaskQueue> *_Nullable)taskQueue;Parameters
nameThe channel name.
messengerThe binary messenger.
codecThe method codec.
taskQueueThe FlutterTaskQueue that executes the handler (see -[FlutterBinaryMessenger makeBackgroundTaskQueue]).
-
Invokes the specified Flutter method with the specified arguments, expecting no results.
Declaration
Objective-C
- (void)invokeMethod:(nonnull NSString *)method arguments:(id _Nullable)arguments;Swift
func invokeMethod(_ method: String, arguments: Any?)Parameters
methodThe name of the method to invoke.
argumentsThe arguments. Must be a value supported by the codec of this channel.
-
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;Swift
func invokeMethod(_ method: String, arguments: Any?, result callback: FlutterResult? = nil)Parameters
methodThe name of the method to invoke.
argumentsThe arguments. Must be a value supported by the codec of this channel.
callbackA callback that will be invoked with the asynchronous result. The result will be a
FlutterErrorinstance, if the method call resulted in an error on the Flutter side. Will beFlutterMethodNotImplemented, if the method called was not implemented on the Flutter side. Any other value, includingnil, should be interpreted as successful results. -
Registers a handler for method calls from the Flutter side.
Replaces any existing handler. Use a
nilhandler for unregistering the existing handler.Declaration
Objective-C
- (void)setMethodCallHandler:(FlutterMethodCallHandler _Nullable)handler;Swift
func setMethodCallHandler(_ handler: FlutterMethodCallHandler?)Parameters
handlerThe method call handler.
-
Adjusts the number of messages that will get buffered when sending messages to channels that aren’t fully set up yet. For example, the engine isn’t running yet or the channel’s message handler isn’t set up on the Dart side yet.
Declaration
Objective-C
- (void)resizeChannelBuffer:(NSInteger)newSize;Swift
func resizeBuffer(_ newSize: Int)
View on GitHub
Install in Dash
FlutterMethodChannel Class Reference