From e44af72e8d0380a20892f6ed7113413a81350baa Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 21 Oct 2021 16:02:26 -0700 Subject: [PATCH 1/2] add callback to addNotificationRequest --- ios/RNCPushNotificationIOS.m | 5 ++++- js/index.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ios/RNCPushNotificationIOS.m b/ios/RNCPushNotificationIOS.m index ca683648..a933ce75 100644 --- a/ios/RNCPushNotificationIOS.m +++ b/ios/RNCPushNotificationIOS.m @@ -286,7 +286,8 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification [RCTSharedApplication() scheduleLocalNotification:notification]; } -RCT_EXPORT_METHOD(addNotificationRequest:(UNNotificationRequest*)request) +RCT_EXPORT_METHOD(addNotificationRequest:(UNNotificationRequest*)request + (RCTResponseSenderBlock)callback) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; NSString *imageUrl = request.content.userInfo[@"image"]; @@ -306,6 +307,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification if (!error) { NSLog(@"image notifier request success"); } + callback(error); } ]; } @@ -316,6 +318,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification if (!error) { NSLog(@"notifier request success"); } + callback(error); } ]; } diff --git a/js/index.js b/js/index.js index b2cd9502..924efd68 100644 --- a/js/index.js +++ b/js/index.js @@ -141,7 +141,7 @@ class PushNotificationIOS { * Sends notificationRequest to notification center at specified firedate. * Fires immediately if firedate is not set. */ - static addNotificationRequest(request: NotificationRequest) { + static addNotificationRequest(request: NotificationRequest, callback: Function = () =>{}) { const handledRequest = request.fireDate instanceof Date ? {...request, fireDate: request.fireDate.toISOString()} @@ -151,7 +151,7 @@ class PushNotificationIOS { repeatsComponent: request.repeatsComponent || {}, }; - RNCPushNotificationIOS.addNotificationRequest(finalRequest); + RNCPushNotificationIOS.addNotificationRequest(finalRequest, callback); } /** From 2e8287039ab6c41503ee60a3a2cc71ba9f9ecbae Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 22 Oct 2021 14:19:18 -0700 Subject: [PATCH 2/2] fix syntax --- ios/RNCPushNotificationIOS.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ios/RNCPushNotificationIOS.m b/ios/RNCPushNotificationIOS.m index a933ce75..813cfa7f 100644 --- a/ios/RNCPushNotificationIOS.m +++ b/ios/RNCPushNotificationIOS.m @@ -286,8 +286,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification [RCTSharedApplication() scheduleLocalNotification:notification]; } -RCT_EXPORT_METHOD(addNotificationRequest:(UNNotificationRequest*)request - (RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(addNotificationRequest:(UNNotificationRequest*)request callback:(RCTResponseSenderBlock)callback) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; NSString *imageUrl = request.content.userInfo[@"image"];