diff --git a/native/ios/NotificationService/NotificationService.mm b/native/ios/NotificationService/NotificationService.mm --- a/native/ios/NotificationService/NotificationService.mm +++ b/native/ios/NotificationService/NotificationService.mm @@ -1,6 +1,9 @@ #import "NotificationService.h" +#import "Logger.h" #import "TemporaryMessageStorage.h" +NSString *const backgroundNotificationTypeKey = @"backgroundNotifType"; + @interface NotificationService () @property(nonatomic, strong) void (^contentHandler) @@ -17,6 +20,12 @@ contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; + + if ([self isRescind:self.bestAttemptContent.userInfo]) { + self.contentHandler([[UNNotificationContent alloc] init]); + return; + } + NSString *message = self.bestAttemptContent.userInfo[@"messageInfos"]; if (message) { TemporaryMessageStorage *temporaryStorage = @@ -32,7 +41,20 @@ // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified // content, otherwise the original push payload will be used. + if ([self isRescind:self.bestAttemptContent.userInfo]) { + // If we get to this place it means we were unable to + // remove relevant notification from notification center in + // in time given to NSE to process notification. + // It is an extremely unlikely to happen. + comm::Logger::log("NSE: Exceeded time limit to rescind a notification."); + self.contentHandler([[UNNotificationContent alloc] init]); + } self.contentHandler(self.bestAttemptContent); } +- (BOOL)isRescind:(NSDictionary *)payload { + return payload[backgroundNotificationTypeKey] && + [payload[backgroundNotificationTypeKey] isEqualToString:@"CLEAR"]; +} + @end