From 1a170ba48458b25c1154222272ad5a2583d502ab Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 11 May 2018 11:47:31 -0400 Subject: [PATCH] Simplify debug notifications. --- Signal/src/AppDelegate.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 4bed6ee04..e14c6b6f7 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -533,11 +533,24 @@ static NSTimeInterval launchStartedAt; // When opening the app from a notification, // AppDelegate.didReceiveLocalNotification will always // be called _before_ we become active. - [application cancelAllLocalNotifications]; + [self cancelAllNotifications]; DDLogInfo(@"%@ applicationDidBecomeActive completed.", self.logTag); } +- (void)cancelAllNotifications +{ + DDLogInfo(@"%@ cancelAllNotifications.", self.logTag); + + // This will cancel all "scheduled" local notifications that haven't + // been presented yet. + [UIApplication.sharedApplication cancelAllLocalNotifications]; + // To clear all already presented local notifications, we need to + // set the app badge number to zero after setting it to a non-zero value. + [UIApplication sharedApplication].applicationIconBadgeNumber = 1; + [UIApplication sharedApplication].applicationIconBadgeNumber = 0; +} + - (void)enableBackgroundRefreshIfNecessary { [AppReadiness runNowOrWhenAppIsReady:^{ @@ -653,7 +666,7 @@ static NSTimeInterval launchStartedAt; DDLogWarn(@"%@ applicationWillResignActive.", self.logTag); // Clear all notifications whenever we become inactive. - [application cancelAllLocalNotifications]; + [self cancelAllNotifications]; [DDLog flushLog]; }