diff --git a/LokiPushNotificationService/NotificationServiceExtension.swift b/LokiPushNotificationService/NotificationServiceExtension.swift index f5aa06a9e..fe2e628dd 100644 --- a/LokiPushNotificationService/NotificationServiceExtension.swift +++ b/LokiPushNotificationService/NotificationServiceExtension.swift @@ -16,6 +16,14 @@ final class NotificationServiceExtension : UNNotificationServiceExtension { self.contentHandler = contentHandler notificationContent = (request.content.mutableCopy() as? UNMutableNotificationContent) + var isMainAppActive = false + if let sharedUserDefaults = UserDefaults(suiteName: "group.com.loki-project.loki-messenger") { + isMainAppActive = sharedUserDefaults.bool(forKey: "isMainAppActive") + } + print("[Ryan debug] isMainAppActive \(isMainAppActive)") + // If the main app is running, skip the whole process + guard !isMainAppActive else { return self.completeWithFailure(content: notificationContent!) } + // The code using DispatchQueue.main.async { self.setUpIfNecessary() { Modify the notification content } } will somehow cause a freeze when a second PN comes DispatchQueue.main.sync { self.setUpIfNecessary() {} } diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 4c4767cea..02f47365f 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -306,6 +306,10 @@ static NSTimeInterval launchStartedAt; if (CurrentAppContext().isRunningTests) { return; } + + NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"]; + [sharedUserDefaults setBool:true forKey:@"isMainAppActive"]; + [sharedUserDefaults synchronize]; [self ensureRootViewController]; @@ -333,6 +337,10 @@ static NSTimeInterval launchStartedAt; } [self clearAllNotificationsAndRestoreBadgeCount]; + + NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"]; + [sharedUserDefaults setBool:false forKey:@"isMainAppActive"]; + [sharedUserDefaults synchronize]; [DDLog flushLog]; }