Flutter 和原生混合开发出现Unhandled Exception: MissingPluginException

出现问题

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

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];
}

你可能感兴趣的:(Flutter 和原生混合开发出现Unhandled Exception: MissingPluginException)