iOS Flutter 混编遇到的问题及解决办法

iOS Flutter 混编遇到的问题及解决办法,第1张

1. Unhandled Exception: MissingPluginException(No implementation found for method …

Flutter中使用的三方插件,在与插件通信时无法找到插件

解决:要添加这句:[GeneratedPluginRegistrant registerWithRegistry:flutterViewController];
#import 
#import 

FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithProject:nil initialRoute:@"mainpage" nibName:nil bundle:nil];
            flutterViewController.modalPresentationStyle = UIModalPresentationFullScreen;
            // 注册我们的module里面的桥接
            [GeneratedPluginRegistrant registerWithRegistry:flutterViewController];
            // 要与main.dart中一致
            NSString *channelName = @"main";
            //单项通信管道,Flutter向原生发送消息
            FlutterMethodChannel *messageChannel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:flutterViewController.binaryMessenger];

            [messageChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
                //可以在这里实现flutter发给原生要实现的方法
                NSLog(@"%@,%@",call.method,call.arguments);
                if ([call.method isEqualToString:@"getUser"]) {
                    result(_user);
            }];
            
            [self.navigationController pushViewController:flutterViewController animated:YES];
2. platform exception(channel-error, unable to establish connection on channel., null, null)

同样也是上边的解决方法。


未完待续

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/990417.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存