diff --git a/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm b/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm --- a/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm +++ b/native/ios/Comm/CommIOSNotifications/CommIOSNotifications.mm @@ -294,6 +294,25 @@ }]; } +RCT_EXPORT_METHOD(completeNotif + : (NSString *)completionKey fetchResult + : (UIBackgroundFetchResult)result) { + RCTRemoteNotificationCallback completionHandler = + self.remoteNotificationCallbacks[completionKey]; + if (!completionHandler) { + NSLog(@"There is no completion handler with key: %@", completionKey); + return; + } + completionHandler(result); + [self.remoteNotificationCallbacks removeObjectForKey:completionKey]; +} + +RCT_EXPORT_METHOD(setBadgesCount : (int)count) { + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]; + }); +} + RCT_EXPORT_METHOD(consumeBackgroundQueue) { CommIOSNotificationsBridgeQueue.sharedInstance.jsReady = YES; @@ -337,4 +356,36 @@ }]; } +RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { + [UNUserNotificationCenter + .currentNotificationCenter removeAllDeliveredNotifications]; +} + +RCT_EXPORT_METHOD(removeDeliveredNotifications + : (NSArray *)identifiers) { + [UNUserNotificationCenter.currentNotificationCenter + removeDeliveredNotificationsWithIdentifiers:identifiers]; +} + +RCT_EXPORT_METHOD(getDeliveredNotifications + : (RCTResponseSenderBlock)callback) { + [UNUserNotificationCenter.currentNotificationCenter + getDeliveredNotificationsWithCompletionHandler:^( + NSArray *_Nonnull notifications) { + NSMutableArray *formattedNotifications = + [NSMutableArray new]; + + for (UNNotification *notification in notifications) { + [formattedNotifications + addObject: + [CommIOSNotifications + parseNotificationToJSReadableObject:notification.request + .content.userInfo + withRequestIdentifier:notification.request + .identifier]]; + } + callback(@[ formattedNotifications ]); + }]; +} + @end