Skip to content

Commit

Permalink
Merge pull request #467 from WalletConnect/background-task-fix
Browse files Browse the repository at this point in the history
[Hotfix] Fix background task not invalidated
  • Loading branch information
llbartekll authored Aug 24, 2022
2 parents 8cddac9 + 344041c commit 3ce0e60
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
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

0 comments on commit 3ce0e60

Please sign in to comment.