From fc7dec04aa1352d3c8623f1b7a828381119105b7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 17 May 2017 15:44:49 -0400 Subject: [PATCH 1/2] Fix missing notifications. // FREEBIE --- Signal/src/environment/NotificationsManager.m | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 4b6f4fe1f..699b4d5fc 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -219,7 +219,7 @@ // Replace any existing notification // e.g. when an "Incoming Call" notification gets replaced with a "Missed Call" notification. if (self.currentNotifications[identifier]) { - [self cancelNotificationWithIdentifier:identifier]; + [self cancelNotificationWithIdentifierMainThread:identifier]; } [[UIApplication sharedApplication] scheduleLocalNotification:notification]; @@ -232,18 +232,24 @@ - (void)cancelNotificationWithIdentifier:(NSString *)identifier { dispatch_async(dispatch_get_main_queue(), ^{ - UILocalNotification *notification = self.currentNotifications[identifier]; - if (!notification) { - DDLogWarn( - @"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier); - return; - } - [self.currentNotifications removeObjectForKey:identifier]; - - [[UIApplication sharedApplication] cancelLocalNotification:notification]; + [self cancelNotificationWithIdentifierMainThread:identifier]; }); } +- (void)cancelNotificationWithIdentifierMainThread:(NSString *)identifier +{ + OWSAssert([NSThread isMainThread]); + + UILocalNotification *notification = self.currentNotifications[identifier]; + if (!notification) { + DDLogWarn(@"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier); + return; + } + [self.currentNotifications removeObjectForKey:identifier]; + + [[UIApplication sharedApplication] cancelLocalNotification:notification]; +} + #pragma mark - Logging + (NSString *)tag From 5fd93eace0fcc3e97a14171edb99b0c2f9f93a10 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 17 May 2017 15:45:00 -0400 Subject: [PATCH 2/2] Fix missing notifications. // FREEBIE --- Signal/src/environment/NotificationsManager.m | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 699b4d5fc..f7de7f453 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -14,6 +14,7 @@ #import #import #import +#import @interface NotificationsManager () @@ -215,11 +216,11 @@ - (void)presentNotification:(UILocalNotification *)notification identifier:(NSString *)identifier { - dispatch_async(dispatch_get_main_queue(), ^{ + DispatchMainThreadSafe(^{ // Replace any existing notification // e.g. when an "Incoming Call" notification gets replaced with a "Missed Call" notification. if (self.currentNotifications[identifier]) { - [self cancelNotificationWithIdentifierMainThread:identifier]; + [self cancelNotificationWithIdentifier:identifier]; } [[UIApplication sharedApplication] scheduleLocalNotification:notification]; @@ -231,23 +232,17 @@ - (void)cancelNotificationWithIdentifier:(NSString *)identifier { - dispatch_async(dispatch_get_main_queue(), ^{ - [self cancelNotificationWithIdentifierMainThread:identifier]; - }); -} - -- (void)cancelNotificationWithIdentifierMainThread:(NSString *)identifier -{ - OWSAssert([NSThread isMainThread]); - - UILocalNotification *notification = self.currentNotifications[identifier]; - if (!notification) { - DDLogWarn(@"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier); - return; - } - [self.currentNotifications removeObjectForKey:identifier]; + DispatchMainThreadSafe(^{ + UILocalNotification *notification = self.currentNotifications[identifier]; + if (!notification) { + DDLogWarn( + @"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier); + return; + } + [self.currentNotifications removeObjectForKey:identifier]; - [[UIApplication sharedApplication] cancelLocalNotification:notification]; + [[UIApplication sharedApplication] cancelLocalNotification:notification]; + }); } #pragma mark - Logging