From 7fd3d665dc6f2148f924aa05313e739739dd7581 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 17 Nov 2017 13:46:14 -0500 Subject: [PATCH] Request contacts as necessary when app is brought back to the foreground // FREEBIE --- Signal/src/ViewControllers/HomeViewController.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Signal/src/ViewControllers/HomeViewController.m b/Signal/src/ViewControllers/HomeViewController.m index 15cb0c07d..9e96251fc 100644 --- a/Signal/src/ViewControllers/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeViewController.m @@ -128,6 +128,10 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidBecomeActive:) + name:UIApplicationDidBecomeActiveNotification + object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yapDatabaseModified:) name:YapDatabaseModifiedNotification @@ -490,6 +494,19 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; self.isAppInBackground = YES; } +- (void)applicationDidBecomeActive:(NSNotification *)notification +{ + // It's possible a thread was created while we where in the background. But since we don't honor contact + // requests unless the app is in the foregrond, we must check again here upon becoming active. + if ([TSThread numberOfKeysInCollection] > 0) { + [self.contactsManager requestSystemContactsOnceWithCompletion:^(NSError *_Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateReminderViews]; + }); + }]; + } +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];