From 15c78df45faeeedb899fe2d5c3af48c35d888fb4 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. (flutter/engine#12999) --- .../Source/FlutterPluginAppLifeCycleDelegate.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index 8c7877b44d5..8358551a354 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -56,6 +56,7 @@ static const SEL selectorsHandledByPlugins[] = { [self addObserverFor:UIApplicationWillTerminateNotification selector:@selector(handleWillTerminate:)]; _delegates = [[NSPointerArray weakObjectsPointerArray] retain]; + _debugBackgroundTask = UIBackgroundTaskInvalid; } return self; } @@ -143,7 +144,10 @@ static BOOL isPowerOfTwo(NSUInteger x) { _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 @@ static BOOL isPowerOfTwo(NSUInteger x) { - (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) {