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];
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容