From f3f9ab0ff290d79c3234a5a981dd4aaa4873af57 Mon Sep 17 00:00:00 2001 From: Pepsin Ye Date: Fri, 18 Dec 2020 14:43:03 +0800 Subject: [PATCH 1/2] Fix background crash when FlutterView is being presented while app being move to background --- .../darwin/ios/framework/Source/FlutterViewController.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 7f593583a54c8..975324978de06 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -629,6 +629,9 @@ - (void)viewDidAppear:(BOOL)animated { [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"]; [super viewDidAppear:animated]; + if (UIApplication.sharedApplication.applicationState == UIApplicationStateBackground) { + [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.paused"]; + } } - (void)viewWillDisappear:(BOOL)animated { From ed528ec7b2f10a228135506ca1ad8bb1f2aa24f7 Mon Sep 17 00:00:00 2001 From: Pepsin Ye Date: Fri, 8 Jan 2021 15:58:59 +0800 Subject: [PATCH 2/2] If app not in foreground, don't send resume message --- .../darwin/ios/framework/Source/FlutterViewController.mm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 975324978de06..6b9a2277dbec7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -626,12 +626,10 @@ - (void)viewDidAppear:(BOOL)animated { TRACE_EVENT0("flutter", "viewDidAppear"); [self onUserSettingsChanged:nil]; [self onAccessibilityStatusChanged:nil]; - [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"]; - - [super viewDidAppear:animated]; - if (UIApplication.sharedApplication.applicationState == UIApplicationStateBackground) { - [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.paused"]; + if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { + [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"]; } + [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated {