Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Fix background task not invalidated #467

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
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 @@ -36,7 +36,6 @@ class AutomaticSocketConnectionHandler: SocketConnectionHandler {
}

appStateObserver.onWillEnterForeground = { [unowned self] in
backgroundTaskRegistrar.invalidate()
socket.connect()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import UIKit

protocol BackgroundTaskRegistering {
func register(name: String, completion: @escaping () -> Void)
func invalidate()
}

class BackgroundTaskRegistrar: BackgroundTaskRegistering {
Expand All @@ -15,7 +14,7 @@ class BackgroundTaskRegistrar: BackgroundTaskRegistering {

func register(name: String, completion: @escaping () -> Void) {
#if os(iOS)
backgroundTaskID = .invalid
invalidateIfNeeded()
backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: name) { [unowned self] in
UIApplication.shared.endBackgroundTask(backgroundTaskID)
backgroundTaskID = .invalid
Expand All @@ -24,7 +23,7 @@ class BackgroundTaskRegistrar: BackgroundTaskRegistering {
#endif
}

func invalidate() {
private func invalidateIfNeeded() {
#if os(iOS)
if backgroundTaskID != .invalid {
UIApplication.shared.endBackgroundTask(backgroundTaskID)
Expand Down