Flutter Engine
FlutterBinaryMessenger.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FLUTTERBINARYMESSENGER_H_
6 #define FLUTTER_FLUTTERBINARYMESSENGER_H_
7 
8 #import <Foundation/Foundation.h>
9 
10 #import "FlutterMacros.h"
11 
13 /**
14  * A message reply callback.
15  *
16  * Used for submitting a binary reply back to a Flutter message sender. Also used
17  * in for handling a binary message reply received from Flutter.
18  *
19  * @param reply The reply.
20  */
21 typedef void (^FlutterBinaryReply)(NSData* _Nullable reply);
22 
23 /**
24  * A strategy for handling incoming binary messages from Flutter and to send
25  * asynchronous replies back to Flutter.
26  *
27  * @param message The message.
28  * @param reply A callback for submitting an asynchronous reply to the sender.
29  */
30 typedef void (^FlutterBinaryMessageHandler)(NSData* _Nullable message, FlutterBinaryReply reply);
31 
33 
34 /**
35  * A facility for communicating with the Flutter side using asynchronous message
36  * passing with binary messages.
37  *
38  * Implementated by:
39  * - `FlutterBasicMessageChannel`, which supports communication using structured
40  * messages.
41  * - `FlutterMethodChannel`, which supports communication using asynchronous
42  * method calls.
43  * - `FlutterEventChannel`, which supports commuication using event streams.
44  */
46 @protocol FlutterBinaryMessenger <NSObject>
47 /**
48  * Sends a binary message to the Flutter side on the specified channel, expecting
49  * no reply.
50  *
51  * @param channel The channel name.
52  * @param message The message.
53  */
54 - (void)sendOnChannel:(NSString*)channel message:(NSData* _Nullable)message;
55 
56 /**
57  * Sends a binary message to the Flutter side on the specified channel, expecting
58  * an asynchronous reply.
59  *
60  * @param channel The channel name.
61  * @param message The message.
62  * @param callback A callback for receiving a reply.
63  */
64 - (void)sendOnChannel:(NSString*)channel
65  message:(NSData* _Nullable)message
66  binaryReply:(FlutterBinaryReply _Nullable)callback;
67 
68 /**
69  * Registers a message handler for incoming binary messages from the Flutter side
70  * on the specified channel.
71  *
72  * Replaces any existing handler. Use a `nil` handler for unregistering the
73  * existing handler.
74  *
75  * @param channel The channel name.
76  * @param handler The message handler.
77  * @return An identifier that represents the connection that was just created to the channel.
78  */
79 - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(NSString*)channel
80  binaryMessageHandler:
81  (FlutterBinaryMessageHandler _Nullable)handler;
82 
83 /**
84  * Clears out a channel's message handler if that handler is still the one that
85  * was created as a result of
86  * `setMessageHandlerOnChannel:binaryMessageHandler:`.
87  *
88  * @param connection The result from `setMessageHandlerOnChannel:binaryMessageHandler:`.
89  */
90 - (void)cleanupConnection:(FlutterBinaryMessengerConnection)connection;
91 @end
93 #endif // FLUTTER_FLUTTERBINARYMESSENGER_H_
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
int64_t FlutterBinaryMessengerConnection
#define FLUTTER_EXPORT