BasicMessageChannel

前言:BasicMessageChannel是flutter官方的一个通讯手段,用于混合工程中flutter和原生的通讯。
用法:
iOS端:

FBFlutterViewContainer * fvc  = [[FBFlutterViewContainer alloc]init];
[fvc setName:@"FollowingPage" uniqueId:nil params:nil opaque:true];
[weakSelf.navigationController pushViewController:fvc animated:YES];
[UIApplication sharedApplication].keyWindow.rootViewController;
        FlutterBasicMessageChannel* messageChannel = [FlutterBasicMessageChannel messageChannelWithName:@"flutter_and_native_channel_name" binaryMessenger:fvc.binaryMessenger];
[messageChannel sendMessage:@{@"flutter messag":@"native向flutter发送了参数\n"}];

Fluttter端:

static const messageChannel =
      BasicMessageChannel('flutter_and_native_channel_name', StandardMessageCodec());

channel.setMessageHandler((message) async{
  // 处理接收到的消息
    print('Received message: $message');
    return " ";
});

其中flutter端的接收也可以放到main里,说明不一定是跳转过来的页才能接收消息。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容