Flutter 和原生混合开发出现Unhandled Excep

2019-08-16  本文已影响0人  iOS_bird

出现问题

由于项目需求需要使用原生导航栏功能,结果出现

Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
     FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
    UINavigationController* rootViewController = [[UINavigationController alloc]             initWithRootViewController:controller];
    rootViewController.navigationBar.hidden = YES;
    self.window.rootViewController = rootViewController;
 [GeneratedPluginRegistrant registerWithRegistry:self];
    
   // return YES;
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

项目会出现错误

Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

解决方法:

[GeneratedPluginRegistrant registerWithRegistry:controller]; 手动注册插件
代码如下:

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
     FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
    UINavigationController* rootViewController = [[UINavigationController alloc]             initWithRootViewController:controller];
    rootViewController.navigationBar.hidden = YES;
    self.window.rootViewController = rootViewController;
// [GeneratedPluginRegistrant registerWithRegistry:self];
    [GeneratedPluginRegistrant registerWithRegistry:controller];
   // return YES;
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
上一篇 下一篇

猜你喜欢

热点阅读