Skip to content

Commit

Permalink
VIT-7090: App state tracker not detecting "app launched into backgrou…
Browse files Browse the repository at this point in the history
…nd" (#228)
  • Loading branch information
andersio authored Aug 5, 2024
1 parent 818c660 commit 3be8787
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/VitalHealthKit/HealthKit/AppStateTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ final class AppStateTracker {
}

init() {
NotificationCenter.default.addObserver(
self,
selector: #selector(appDidFinishLaunching),
name: UIApplication.didFinishLaunchingNotification,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(appWillEnterForeground),
Expand Down Expand Up @@ -48,6 +55,13 @@ final class AppStateTracker {
lock.withLock { self.onChange = onChange }
}

@objc
func appDidFinishLaunching() {
if UIApplication.shared.applicationState == .background {
transition(to: .background)
}
}

@objc
func appWillEnterForeground() {
transition(to: .foreground)
Expand Down

0 comments on commit 3be8787

Please sign in to comment.