美文网首页
Flutter 和原生混合开发出现Unhandled Excep

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

作者: iOS_bird | 来源:发表于2019-08-16 17:47 被阅读0次

    出现问题

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

    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 Excep

          本文链接:https://www.haomeiwen.com/subject/nymqsctx.html