fix homeVC not refreshing because of PN

This commit is contained in:
Ryan ZHAO 2020-07-31 14:20:09 +10:00
parent 04c6610e10
commit 4fe78bdda4
2 changed files with 16 additions and 0 deletions

View File

@ -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() {} }

View File

@ -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];
}