From dc691d597b762fd98beaffef5d94262c67bfdc22 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 19 Feb 2019 16:45:15 -0600 Subject: [PATCH] Back active flag with actual applicationState --- Loop/View Controllers/ChartsTableViewController.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Loop/View Controllers/ChartsTableViewController.swift b/Loop/View Controllers/ChartsTableViewController.swift index 3642a25628..ca936104d0 100644 --- a/Loop/View Controllers/ChartsTableViewController.swift +++ b/Loop/View Controllers/ChartsTableViewController.swift @@ -86,7 +86,7 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg let notificationCenter = NotificationCenter.default notificationObservers += [ - notificationCenter.addObserver(forName: .UIApplicationWillResignActive, object: UIApplication.shared, queue: .main) { [weak self] _ in + notificationCenter.addObserver(forName: .UIApplicationDidEnterBackground, object: UIApplication.shared, queue: .main) { [weak self] _ in self?.active = false }, notificationCenter.addObserver(forName: .UIApplicationDidBecomeActive, object: UIApplication.shared, queue: .main) { [weak self] _ in @@ -94,8 +94,6 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg } ] - active = UIApplication.shared.applicationState == .active - let gestureRecognizer = UILongPressGestureRecognizer() gestureRecognizer.delegate = self gestureRecognizer.minimumPressDuration = 0.1 @@ -168,8 +166,11 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg // References to registered notification center observers var notificationObservers: [Any] = [] - var active: Bool = false { - didSet { + var active: Bool { + get { + return UIApplication.shared.applicationState == .active + } + set { log.debug("[reloadData] for app change to active: %d", active) reloadData() }