diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 16ce8d25a..783ecaf1b 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -644,6 +644,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni { NSLog(@"[AppDelegate] applicationDidBecomeActive"); + [self.pushNotificationService applicationDidBecomeActive]; + if ([self.localAuthenticationService shouldShowPinCode]) { if (self.setPinCoordinatorBridgePresenter) diff --git a/Riot/Categories/UNUserNotificationCenter.swift b/Riot/Categories/UNUserNotificationCenter.swift index 10389f425..b493976fc 100644 --- a/Riot/Categories/UNUserNotificationCenter.swift +++ b/Riot/Categories/UNUserNotificationCenter.swift @@ -30,4 +30,15 @@ import UserNotifications } } + func removeCallNotifications() { + UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in + // get identifiers of notifications whose category identifiers are "TO_BE_REMOVED" + let identifiersToBeRemoved = notifications.compactMap({ $0.request.content.categoryIdentifier == Constants.callNotificationsCategoryIdentifier ? $0.request.identifier : nil }) + + NSLog("[UNUserNotificationCenter] removeUnwantedNotifications: Removing \(identifiersToBeRemoved.count) notifications.") + // remove the notifications with these id's + UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiersToBeRemoved) + } + } + } diff --git a/Riot/Managers/PushNotification/PushNotificationService.h b/Riot/Managers/PushNotification/PushNotificationService.h index c0c6ff98c..5af662144 100644 --- a/Riot/Managers/PushNotification/PushNotificationService.h +++ b/Riot/Managers/PushNotification/PushNotificationService.h @@ -68,6 +68,9 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)applicationWillEnterForeground; +/// Method to be called when the application becomes active. +- (void)applicationDidBecomeActive; + /** Remove delivered notifications for a given room id except call notifications diff --git a/Riot/Managers/PushNotification/PushNotificationService.m b/Riot/Managers/PushNotification/PushNotificationService.m index 801ff4434..dcad27628 100644 --- a/Riot/Managers/PushNotification/PushNotificationService.m +++ b/Riot/Managers/PushNotification/PushNotificationService.m @@ -137,6 +137,12 @@ [[UNUserNotificationCenter currentNotificationCenter] removeUnwantedNotifications]; } +- (void)applicationDidBecomeActive +{ + [[UNUserNotificationCenter currentNotificationCenter] removeUnwantedNotifications]; + [[UNUserNotificationCenter currentNotificationCenter] removeCallNotifications]; +} + #pragma mark - Private Methods - (void)configurePushKit