diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 8ab6c4d2cc..c4d7f6d65b 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -154,21 +154,16 @@ static constexpr int kNumProfilerSamplesPerSec = 5; name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + [center addObserver:self + selector:@selector(applicationWillEnterForeground:) + name:UIApplicationWillEnterForegroundNotification + object:nil]; + [center addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; - [center addObserver:self - selector:@selector(applicationBecameActive:) - name:UIApplicationDidBecomeActiveNotification - object:nil]; - - [center addObserver:self - selector:@selector(applicationWillResignActive:) - name:UIApplicationWillResignActiveNotification - object:nil]; - [center addObserver:self selector:@selector(onLocaleUpdated:) name:NSCurrentLocaleDidChangeNotification @@ -610,7 +605,8 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS _threadHost->io_thread->GetTaskRunner() // io ); - _isGpuDisabled = [UIApplication sharedApplication].applicationState != UIApplicationStateActive; + _isGpuDisabled = + [UIApplication sharedApplication].applicationState == UIApplicationStateBackground; // Create the shell. This is a blocking operation. std::unique_ptr shell = flutter::Shell::Create( /*platform_data=*/std::move(platformData), @@ -886,15 +882,12 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS #pragma mark - Notifications -- (void)applicationBecameActive:(NSNotification*)notification { +- (void)applicationWillEnterForeground:(NSNotification*)notification { [self setIsGpuDisabled:NO]; } -- (void)applicationWillResignActive:(NSNotification*)notification { - [self setIsGpuDisabled:YES]; -} - - (void)applicationDidEnterBackground:(NSNotification*)notification { + [self setIsGpuDisabled:YES]; [self notifyLowMemory]; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 4f562cb529..7bf5b0ed03 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -743,12 +743,12 @@ static void sendFakeTouchEvent(FlutterEngine* engine, - (void)applicationWillResignActive:(NSNotification*)notification { TRACE_EVENT0("flutter", "applicationWillResignActive"); - [self surfaceUpdated:NO]; [self goToApplicationLifecycle:@"AppLifecycleState.inactive"]; } - (void)applicationDidEnterBackground:(NSNotification*)notification { TRACE_EVENT0("flutter", "applicationDidEnterBackground"); + [self surfaceUpdated:NO]; [self goToApplicationLifecycle:@"AppLifecycleState.paused"]; }