Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Started setting our debug background task id to invalid #12999

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ - (instancetype)init {
[self addObserverFor:UIApplicationWillTerminateNotification
selector:@selector(handleWillTerminate:)];
_delegates = [[NSPointerArray weakObjectsPointerArray] retain];
_debugBackgroundTask = UIBackgroundTaskInvalid;
}
return self;
}
Expand Down Expand Up @@ -143,7 +144,10 @@ - (void)handleDidEnterBackground:(NSNotification*)notification {
_debugBackgroundTask = [application
beginBackgroundTaskWithName:@"Flutter debug task"
expirationHandler:^{
[application endBackgroundTask:_debugBackgroundTask];
if (_debugBackgroundTask != UIBackgroundTaskInvalid) {
[application endBackgroundTask:_debugBackgroundTask];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be done in dealloc as well (add-to-app where this delegate may actually be deallocated)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. The background task has a retain on the FlutterPluginAppLifeCycleDelegate so it can't be dealloced while it is running.

_debugBackgroundTask = UIBackgroundTaskInvalid;
}
FML_LOG(WARNING)
<< "\nThe OS has terminated the Flutter debug connection for being "
"inactive in the background for too long.\n\n"
Expand All @@ -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<FlutterApplicationLifeCycleDelegate>* delegate in _delegates) {
if (!delegate) {
Expand Down