Skip to content

Commit b03d42b

Browse files
authored
Back active flag with actual applicationState (#892)
1 parent 849813c commit b03d42b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Loop/View Controllers/ChartsTableViewController.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg
8686

8787
let notificationCenter = NotificationCenter.default
8888
notificationObservers += [
89-
notificationCenter.addObserver(forName: .UIApplicationWillResignActive, object: UIApplication.shared, queue: .main) { [weak self] _ in
89+
notificationCenter.addObserver(forName: .UIApplicationDidEnterBackground, object: UIApplication.shared, queue: .main) { [weak self] _ in
9090
self?.active = false
9191
},
9292
notificationCenter.addObserver(forName: .UIApplicationDidBecomeActive, object: UIApplication.shared, queue: .main) { [weak self] _ in
9393
self?.active = true
9494
}
9595
]
9696

97-
active = UIApplication.shared.applicationState == .active
98-
9997
let gestureRecognizer = UILongPressGestureRecognizer()
10098
gestureRecognizer.delegate = self
10199
gestureRecognizer.minimumPressDuration = 0.1
@@ -168,8 +166,11 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg
168166
// References to registered notification center observers
169167
var notificationObservers: [Any] = []
170168

171-
var active: Bool = false {
172-
didSet {
169+
var active: Bool {
170+
get {
171+
return UIApplication.shared.applicationState == .active
172+
}
173+
set {
173174
log.debug("[reloadData] for app change to active: %d", active)
174175
reloadData()
175176
}

0 commit comments

Comments
 (0)