Modify views to observe changes when active, not just foreground.

This commit is contained in:
Matthew Chen 2018-05-31 11:27:07 -04:00
parent 812210a63c
commit fefc9843b1
6 changed files with 18 additions and 4 deletions

View File

@ -4441,7 +4441,7 @@ typedef enum : NSUInteger {
- (void)updateShouldObserveDBModifications
{
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
BOOL isAppForegroundAndActive = CurrentAppContext().isAppForegroundAndActive;
self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive;
}

View File

@ -485,7 +485,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
- (void)updateShouldObserveDBModifications
{
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
BOOL isAppForegroundAndActive = CurrentAppContext().isAppForegroundAndActive;
self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive;
}

View File

@ -156,6 +156,11 @@ NS_ASSUME_NONNULL_BEGIN
return self.reportedApplicationState == UIApplicationStateBackground;
}
- (BOOL)isAppForegroundAndActive
{
return self.reportedApplicationState == UIApplicationStateActive;
}
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler
{

View File

@ -79,8 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateShouldObserveDBModifications
{
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
self.shouldObserveDBModifications = isAppForegroundAndActive;
self.shouldObserveDBModifications = CurrentAppContext().isAppForegroundAndActive;
}
// Don't observe database change notifications when the app is in the background.

View File

@ -55,6 +55,11 @@ NSString *NSStringForUIApplicationState(UIApplicationState value);
// This method is thread-safe.
- (BOOL)isInBackground;
// A convenience accessor for reportedApplicationState.
//
// This method is thread-safe.
- (BOOL)isAppForegroundAndActive;
// Should start a background task if isMainApp is YES.
// Should just return UIBackgroundTaskInvalid if isMainApp is NO.
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:

View File

@ -151,6 +151,11 @@ NS_ASSUME_NONNULL_BEGIN
return self.reportedApplicationState == UIApplicationStateBackground;
}
- (BOOL)isAppForegroundAndActive
{
return self.reportedApplicationState == UIApplicationStateActive;
}
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler
{