diff --git a/native/ios/Comm/AppDelegate.mm b/native/ios/Comm/AppDelegate.mm --- a/native/ios/Comm/AppDelegate.mm +++ b/native/ios/Comm/AppDelegate.mm @@ -26,8 +26,8 @@ @end #endif +#import "CommIOSNotifications.h" #import "Orientation.h" -#import "RNNotifications.h" #import #import @@ -158,13 +158,13 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - [RNNotifications + [CommIOSNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error]; + [CommIOSNotifications didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the notification event. You must call the completion handler @@ -173,6 +173,7 @@ didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler: (void (^)(UIBackgroundFetchResult))completionHandler { + comm::Logger::log("AppDelegate: Received Remote Notification"); BOOL handled = NO; if (notification[@"aps"][@"content-available"] && notification[backgroundNotificationTypeKey]) { @@ -184,8 +185,8 @@ return; } - [RNNotifications didReceiveRemoteNotification:notification - fetchCompletionHandler:completionHandler]; + [CommIOSNotifications didReceiveRemoteNotification:notification + fetchCompletionHandler:completionHandler]; } - (BOOL)handleBackgroundNotification:(NSDictionary *)notification @@ -202,22 +203,9 @@ comm::ThreadOperations::updateSQLiteUnreadStatus(threadID, false); }); } - [[UNUserNotificationCenter currentNotificationCenter] - getDeliveredNotificationsWithCompletionHandler:^( - NSArray *notifications) { - for (UNNotification *notif in notifications) { - if ([notification[@"notificationId"] - isEqual:notif.request.content.userInfo[@"id"]]) { - NSArray *identifiers = - [NSArray arrayWithObjects:notif.request.identifier, nil]; - [[UNUserNotificationCenter currentNotificationCenter] - removeDeliveredNotificationsWithIdentifiers:identifiers]; - } - } - dispatch_async(dispatch_get_main_queue(), ^{ - completionHandler(UIBackgroundFetchResultNewData); - }); - }]; + [CommIOSNotifications + clearNotificationFromNotificationsCenter:notification[@"notificationId"] + completionHandler:completionHandler]; return YES; } return NO; @@ -226,7 +214,7 @@ // Required for the localNotification event. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - [RNNotifications didReceiveLocalNotification:notification]; + [CommIOSNotifications didReceiveLocalNotification:notification]; } - (UIInterfaceOrientationMask)application:(UIApplication *)application diff --git a/native/push/ios.js b/native/push/ios.js --- a/native/push/ios.js +++ b/native/push/ios.js @@ -1,6 +1,8 @@ // @flow -import NotificationsIOS from 'react-native-notifications'; +import { NativeModules } from 'react-native'; + +const { CommIOSNotifications } = NativeModules; type PushPermissions = { alert?: boolean, badge?: boolean, sound?: boolean }; @@ -12,7 +14,7 @@ firstRun = false; if (!permissionNeeded) { - const permissions: PushPermissions = await NotificationsIOS.checkPermissions(); + const permissions: PushPermissions = await CommIOSNotifications.checkPermissions(); permissionNeeded = permissionMissing(permissions); } @@ -21,10 +23,10 @@ return; } currentlyActive = true; - await NotificationsIOS.requestPermissions(); + await CommIOSNotifications.requestPermissions(); } - NotificationsIOS.consumeBackgroundQueue(); + CommIOSNotifications.consumeBackgroundQueue(); } function iosPushPermissionResponseReceived() {