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 @@ -384,6 +384,25 @@ [CommIOSNotifications requestPermissions]; } +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) { // Mark JS Thread as ready [CommIOSNotificationsBridgeQueue sharedInstance].jsIsReady = YES; @@ -440,4 +459,40 @@ }); } +RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { + if ([UNUserNotificationCenter class]) { + UNUserNotificationCenter *center = + [UNUserNotificationCenter currentNotificationCenter]; + [center removeAllDeliveredNotifications]; + } +} + +RCT_EXPORT_METHOD(removeDeliveredNotifications + : (NSArray *)identifiers) { + if ([UNUserNotificationCenter class]) { + UNUserNotificationCenter *center = + [UNUserNotificationCenter currentNotificationCenter]; + [center removeDeliveredNotificationsWithIdentifiers:identifiers]; + } +} + +RCT_EXPORT_METHOD(getDeliveredNotifications + : (RCTResponseSenderBlock)callback) { + if ([UNUserNotificationCenter class]) { + UNUserNotificationCenter *center = + [UNUserNotificationCenter currentNotificationCenter]; + [center getDeliveredNotificationsWithCompletionHandler:^( + NSArray *_Nonnull notifications) { + NSMutableArray *formattedNotifications = + [NSMutableArray new]; + + for (UNNotification *notification in notifications) { + [formattedNotifications + addObject:RCTFormatUNNotification(notification)]; + } + callback(@[ formattedNotifications ]); + }]; + } +} + @end