嗨,我正在尝试使用多个事件通道将数据从本机端流式传输到Flutter iOS Swift端。当我调用以下设置处理程序时,我们只会得到一个回调,我想知道如何区分我收到的EventChannel1还是EventChannel2的事件池。
let EventChannel1 = FlutterEventChannel(name: "stream1",binaryMessenger: controller.binaryMessenger)
let EventChannel2 = FlutterEventChannel(name: "stream2",binaryMessenger: controller.binaryMessenger)
EventChannel1.setStreamHandler(self)
EventChannel2.setStreamHandler(self)
然后我们得到相关的回调函数
func onListen(withArguments arguments: Any?,
eventSink: @escaping FlutterEventSink) -> FlutterError? {
debugPrint("On Listen Call")
EventSink = eventSink//this is for the old event channel now I am using
//two event channel.
//and don't know how to know which event channel is which. on flutter
//app startup I listen both stream.
//and the "on Listen Call" which I print to console print two times
//which indicate the I am listen to both stream.
//but here I don't know how I know if the eventsink is for which event channel.
//I want some condition here but don,t know how to implement. if possible
//something like this if eventchanel.name == eventchannel1
//so that I know which event channel event sink it is and handle it according.
return nil
}
func onCancel(withArguments arguments: Any?) -> FlutterError? {
debugPrint("On cancel Call")
EventSink = nil
return nil
}
如果问题不清楚,请告诉我,这样我就可以更清楚地解释了。
class SwiftStreamHandler: NSObject, FlutterStreamHandler {
。 - pskink