diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ca73791013b6c..079e01b5b659e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -36,7 +36,7 @@ @implementation FlutterViewController { blink::ViewportMetrics _viewportMetrics; BOOL _initialized; BOOL _viewOpaque; - BOOL _engineNeedsLaunch; + BOOL _isEmbedEngine; } #pragma mark - Manage and override all designated initializers @@ -49,7 +49,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine if (self) { _viewOpaque = YES; _engine.reset([engine retain]); - _engineNeedsLaunch = NO; + _isEmbedEngine = FALSE; _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); _weakFactory = std::make_unique>(self); @@ -70,9 +70,9 @@ - (instancetype)initWithProject:(FlutterDartProject*)projectOrNil _engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter" project:projectOrNil allowHeadlessExecution:NO]); + _isEmbedEngine = TRUE; _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); [_engine.get() createShell:nil libraryURI:nil]; - _engineNeedsLaunch = YES; [self loadDefaultSplashScreenView]; [self performCommonViewControllerInitialization]; } @@ -388,10 +388,9 @@ - (void)surfaceUpdated:(BOOL)appeared { - (void)viewWillAppear:(BOOL)animated { TRACE_EVENT0("flutter", "viewWillAppear"); - - if (_engineNeedsLaunch) { + if (_isEmbedEngine) { + [_engine.get() createShell:nil libraryURI:nil]; [_engine.get() launchEngine:nil libraryURI:nil]; - _engineNeedsLaunch = NO; } [_engine.get() setViewController:self]; @@ -501,6 +500,8 @@ - (void)applicationWillEnterForeground:(NSNotification*)notification { // touch is specified in the second argument. - (void)dispatchTouches:(NSSet*)touches pointerDataChangeOverride:(blink::PointerData::Change*)overridden_change { + if (!(self.isViewLoaded && self.view.window)) + return; const CGFloat scale = [UIScreen mainScreen].scale; auto packet = std::make_unique(touches.count);