1. Unhandled Exception: MissingPluginException(No implementation found for method …
Flutter中使用的三方插件,在与插件通信时无法找到插件
解决:要添加这句:[GeneratedPluginRegistrant registerWithRegistry:flutterViewController];
#import <Flutter/Flutter.h>
#import <FlutterPluginRegistrant-umbrella.h>
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)
同样也是上边的解决方法。
未完待续
这篇博客主要讨论了在Flutter开发中遇到的三方插件通信异常问题,如MissingPluginException和PlatformException。作者提供了详细的解决方案,包括在初始化FlutterViewController时注册GeneratedPluginRegistrant,并设置方法调用处理器,确保Flutter与原生之间的通道畅通。此外,还提到了错误处理策略,帮助开发者解决此类问题。

4948

被折叠的 条评论
为什么被折叠?



