From 2123d3a569eb0c3aba0e623ecaf17e40e317e1d3 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 22 Jan 2019 15:03:25 -0800 Subject: [PATCH] Keep engine alive if VC is not deallocated (#7544) --- .../platform/darwin/ios/framework/Source/FlutterEngine.mm | 8 +++++--- .../darwin/ios/framework/Source/FlutterEngine_Internal.h | 1 + .../darwin/ios/framework/Source/FlutterViewController.mm | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 9daf06683083d..10491ffb0c905 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -144,13 +144,15 @@ - (void)setViewController:(FlutterViewController*)viewController { FML_DCHECK(self.iosPlatformView); _viewController = [viewController getWeakPtr]; self.iosPlatformView->SetOwnerViewController(_viewController); - if (!viewController && !_allowHeadlessExecution) { + [self maybeSetupPlatformViewChannels]; +} + +- (void)notifyViewControllerDeallocated { + if (!_allowHeadlessExecution) { [self resetChannels]; _shell.reset(); _threadHost.Reset(); - } else { - [self maybeSetupPlatformViewChannels]; } } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h index 3627ae26e08ae..e21444cc6a9d8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h @@ -43,6 +43,7 @@ - (FlutterTextInputPlugin*)textInputPlugin; - (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil; - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil; +- (void)notifyViewControllerDeallocated; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ca73791013b6c..8df2f3b61dbe9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -430,6 +430,7 @@ - (void)viewDidDisappear:(BOOL)animated { } - (void)dealloc { + [_engine.get() notifyViewControllerDeallocated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; }