Flutter iOS启动跳native页面在跳进flutter

2020-08-20  本文已影响0人  fordG
  1. 自定义appDelegate
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) FlutterEngine *flutterEngine;

@end
  1. 跳到native页面
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  // Override point for customization after application launch.
    
    
    [self initializeWithOptions: launchOptions];
    
    [NOTIFYCENTER addObserver:self selector:@selector(startMyApp) name: BXAccountDidLoginSuccessNotification object:nil];
    return YES;
}
- (FlutterEngine *)flutterEngine {
    if(_flutterEngine == nil){
        _flutterEngine = [[FlutterEngine alloc] initWithName: @"FlutterEngine" project: nil];
    }
    return _flutterEngine;
}
  1. 在你需要的地方去跳到flutter页面,好像可以指定router没研究
- (void)startMyApp{
    [self.flutterEngine runWithEntrypoint: nil];
    FlutterViewController *controller = [[FlutterViewController alloc] initWithEngine: self.flutterEngine nibName: nil bundle: nil];
    [GeneratedPluginRegistrant registerWithRegistry: controller];
    self.window.rootViewController = controller;
}
上一篇下一篇

猜你喜欢

热点阅读