From 4a4882ebe5fe7e40d4b5bfecf872ef4125b10359 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 10 May 2018 13:55:31 -0400 Subject: [PATCH] Add debug notification. --- Signal/src/AppDelegate.m | 9 ++++++++ Signal/src/environment/NotificationsManager.h | 8 ++++++- Signal/src/environment/NotificationsManager.m | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index c9c45a53b..4bed6ee04 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -529,6 +529,12 @@ static NSTimeInterval launchStartedAt; // We want to process up to one local notification per activation, so clear the flag. self.hasReceivedLocalNotification = NO; + // Clear all notifications whenever we become active. + // When opening the app from a notification, + // AppDelegate.didReceiveLocalNotification will always + // be called _before_ we become active. + [application cancelAllLocalNotifications]; + DDLogInfo(@"%@ applicationDidBecomeActive completed.", self.logTag); } @@ -646,6 +652,9 @@ static NSTimeInterval launchStartedAt; DDLogWarn(@"%@ applicationWillResignActive.", self.logTag); + // Clear all notifications whenever we become inactive. + [application cancelAllLocalNotifications]; + [DDLog flushLog]; } diff --git a/Signal/src/environment/NotificationsManager.h b/Signal/src/environment/NotificationsManager.h index 8f18d930a..b7cf0bc2d 100644 --- a/Signal/src/environment/NotificationsManager.h +++ b/Signal/src/environment/NotificationsManager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSCallNotificationsAdaptee.h" @@ -17,6 +17,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)clearAllNotifications; +#ifdef DEBUG + ++ (void)presentDebugNotification; + +#endif + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index cde2590d8..568e8d5d0 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -449,6 +449,11 @@ notification.alertBody = notification.alertBody.filterStringForDisplay; DispatchMainThreadSafe(^{ + if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { + DDLogWarn(@"%@ skipping notification; app is in foreground and active.", self.logTag); + return; + } + // Replace any existing notification // e.g. when an "Incoming Call" notification gets replaced with a "Missed Call" notification. if (self.currentNotifications[identifier]) { @@ -477,6 +482,22 @@ }); } +#ifdef DEBUG + ++ (void)presentDebugNotification +{ + OWSAssertIsOnMainThread(); + + UILocalNotification *notification = [UILocalNotification new]; + notification.category = Signal_Full_New_Message_Category; + notification.soundName = [OWSSounds filenameForSound:OWSSound_DefaultiOSIncomingRingtone]; + notification.alertBody = @"test"; + + [[UIApplication sharedApplication] scheduleLocalNotification:notification]; +} + +#endif + - (void)clearAllNotifications { OWSAssertIsOnMainThread();