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)
同样也是上边的解决方法。
未完待续
|