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 #include "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 /** 33 * A facility for communicating with the Flutter side using asynchronous message 34 * passing with binary messages. 35 * 36 * Implementated by: 37 * - `FlutterBasicMessageChannel`, which supports communication using structured 38 * messages. 39 * - `FlutterMethodChannel`, which supports communication using asynchronous 40 * method calls. 41 * - `FlutterEventChannel`, which supports commuication using event streams. 42 */ 43 FLUTTER_EXPORT 44 @protocol FlutterBinaryMessenger <NSObject> 45 /** 46 * Sends a binary message to the Flutter side on the specified channel, expecting 47 * no reply. 48 * 49 * @param channel The channel name. 50 * @param message The message. 51 */ 52 - (void)sendOnChannel:(NSString*)channel message:(NSData* _Nullable)message; 53 54 /** 55 * Sends a binary message to the Flutter side on the specified channel, expecting 56 * an asynchronous reply. 57 * 58 * @param channel The channel name. 59 * @param message The message. 60 * @param callback A callback for receiving a reply. 61 */ 62 - (void)sendOnChannel:(NSString*)channel 63 message:(NSData* _Nullable)message 64 binaryReply:(FlutterBinaryReply _Nullable)callback; 65 66 /** 67 * Registers a message handler for incoming binary messages from the Flutter side 68 * on the specified channel. 69 * 70 * Replaces any existing handler. Use a `nil` handler for unregistering the 71 * existing handler. 72 * 73 * @param channel The channel name. 74 * @param handler The message handler. 75 */ 76 - (void)setMessageHandlerOnChannel:(NSString*)channel 77 binaryMessageHandler:(FlutterBinaryMessageHandler _Nullable)handler; 78 @end 79 NS_ASSUME_NONNULL_END 80 #endif // FLUTTER_FLUTTERBINARYMESSENGER_H_ 81