| Flutter iOS Embedder |

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_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_HEADERS_FLUTTERBINARYMESSENGER_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_HEADERS_FLUTTERBINARYMESSENGER_H_
7
8 #import <Foundation/Foundation.h>
9
10 #import "FlutterMacros.h"
11
12 NS_ASSUME_NONNULL_BEGIN
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
32 typedef int64_t FlutterBinaryMessengerConnection;
33
34 @protocol FlutterTaskQueue <NSObject>
35 @end
36
37 /**
38 * A facility for communicating with the Flutter side using asynchronous message
39 * passing with binary messages.
40 *
41 * Implementated by:
42 * - `FlutterBasicMessageChannel`, which supports communication using structured
43 * messages.
44 * - `FlutterMethodChannel`, which supports communication using asynchronous
45 * method calls.
46 * - `FlutterEventChannel`, which supports commuication using event streams.
47 */
48 FLUTTER_DARWIN_EXPORT
49 @protocol FlutterBinaryMessenger <NSObject>
50 /// TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
51 @optional
52 - (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue;
53
54 - (FlutterBinaryMessengerConnection)
55 setMessageHandlerOnChannel:(NSString*)channel
56 binaryMessageHandler:(FlutterBinaryMessageHandler _Nullable)handler
57 taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue;
58
59 @required
60 /**
61 * Sends a binary message to the Flutter side on the specified channel, expecting
62 * no reply.
63 *
64 * @param channel The channel name.
65 * @param message The message.
66 */
67 - (void)sendOnChannel:(NSString*)channel message:(NSData* _Nullable)message;
68
69 /**
70 * Sends a binary message to the Flutter side on the specified channel, expecting
71 * an asynchronous reply.
72 *
73 * @param channel The channel name.
74 * @param message The message.
75 * @param callback A callback for receiving a reply.
76 */
77 - (void)sendOnChannel:(NSString*)channel
78 message:(NSData* _Nullable)message
79 binaryReply:(FlutterBinaryReply _Nullable)callback;
80
81 /**
82 * Registers a message handler for incoming binary messages from the Flutter side
83 * on the specified channel.
84 *
85 * Replaces any existing handler. Use a `nil` handler for unregistering the
86 * existing handler.
87 *
88 * @param channel The channel name.
89 * @param handler The message handler.
90 * @return An identifier that represents the connection that was just created to the channel.
91 */
92 - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(NSString*)channel
93 binaryMessageHandler:
94 (FlutterBinaryMessageHandler _Nullable)handler;
95
96 /**
97 * Clears out a channel's message handler if that handler is still the one that
98 * was created as a result of
99 * `setMessageHandlerOnChannel:binaryMessageHandler:`.
100 *
101 * @param connection The result from `setMessageHandlerOnChannel:binaryMessageHandler:`.
102 */
103 - (void)cleanUpConnection:(FlutterBinaryMessengerConnection)connection;
104 @end
105 NS_ASSUME_NONNULL_END
106 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_HEADERS_FLUTTERBINARYMESSENGER_H_
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
FlutterBinaryMessengerConnection
int64_t FlutterBinaryMessengerConnection
Definition: FlutterBinaryMessenger.h:32
FlutterMacros.h
NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49
-[FlutterBinaryMessenger-p makeBackgroundTaskQueue]
NSObject< FlutterTaskQueue > * makeBackgroundTaskQueue()
TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
FlutterTaskQueue-p
Definition: FlutterBinaryMessenger.h:34