From 9f650edd14dd0d74acb3d6ad65eb794b1e4b27e3 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Tue, 8 Oct 2019 13:12:52 -0700 Subject: [PATCH] Started setting our debug background task id to invalid after completion. (#12999) --- .../Source/FlutterPluginAppLifeCycleDelegate.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index 8c7877b44d50b..8358551a354bf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -56,6 +56,7 @@ - (instancetype)init { [self addObserverFor:UIApplicationWillTerminateNotification selector:@selector(handleWillTerminate:)]; _delegates = [[NSPointerArray weakObjectsPointerArray] retain]; + _debugBackgroundTask = UIBackgroundTaskInvalid; } return self; } @@ -143,7 +144,10 @@ - (void)handleDidEnterBackground:(NSNotification*)notification { _debugBackgroundTask = [application beginBackgroundTaskWithName:@"Flutter debug task" expirationHandler:^{ - [application endBackgroundTask:_debugBackgroundTask]; + if (_debugBackgroundTask != UIBackgroundTaskInvalid) { + [application endBackgroundTask:_debugBackgroundTask]; + _debugBackgroundTask = UIBackgroundTaskInvalid; + } FML_LOG(WARNING) << "\nThe OS has terminated the Flutter debug connection for being " "inactive in the background for too long.\n\n" @@ -164,7 +168,10 @@ - (void)handleDidEnterBackground:(NSNotification*)notification { - (void)handleWillEnterForeground:(NSNotification*)notification { UIApplication* application = [UIApplication sharedApplication]; #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG - [application endBackgroundTask:_debugBackgroundTask]; + if (_debugBackgroundTask != UIBackgroundTaskInvalid) { + [application endBackgroundTask:_debugBackgroundTask]; + _debugBackgroundTask = UIBackgroundTaskInvalid; + } #endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG for (NSObject* delegate in _delegates) { if (!delegate) {