diff --git a/docs/installation-ios.md b/docs/installation-ios.md index a0c1f162..57481f3c 100644 --- a/docs/installation-ios.md +++ b/docs/installation-ios.md @@ -143,6 +143,18 @@ Add the following methods: fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ [RNFirebaseMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + willPresentNotification:(UNNotification *)notification + withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { + [RNFirebaseMessaging willPresentNotification:notification withCompletionHandler:completionHandler]; +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center +didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)())completionHandler { + [RNFirebaseMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; +} ``` ### 3.5) Debugging diff --git a/ios/RNFirebase/messaging/RNFirebaseMessaging.h b/ios/RNFirebase/messaging/RNFirebaseMessaging.h index 2a959333..66d66ab2 100644 --- a/ios/RNFirebase/messaging/RNFirebaseMessaging.h +++ b/ios/RNFirebase/messaging/RNFirebaseMessaging.h @@ -21,6 +21,8 @@ typedef void (^RCTNotificationResponseCallback)(); + (void)didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo; + (void)didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull RCTRemoteNotificationCallback)completionHandler; + (void)didReceiveLocalNotification:(nonnull UILocalNotification *)notification; ++ (void)didReceiveNotificationResponse:(nonnull UNNotificationResponse *)response withCompletionHandler:(nonnull RCTNotificationResponseCallback)completionHandler; ++ (void)willPresentNotification:(nonnull UNNotification *)notification withCompletionHandler:(nonnull RCTWillPresentNotificationCallback)completionHandler; #endif @end diff --git a/ios/RNFirebase/messaging/RNFirebaseMessaging.m b/ios/RNFirebase/messaging/RNFirebaseMessaging.m index 63ebb2b6..aa11ce2f 100644 --- a/ios/RNFirebase/messaging/RNFirebaseMessaging.m +++ b/ios/RNFirebase/messaging/RNFirebaseMessaging.m @@ -145,6 +145,24 @@ RCT_EXPORT_MODULE() [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGING_NOTIFICATION_RECEIVED object:self userInfo:@{@"data": data}]; } ++ (void)willPresentNotification:(UNNotification *)notification withCompletionHandler:(nonnull RCTWillPresentNotificationCallback)completionHandler +{ + NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: notification.request.content.userInfo]; + [data setValue:@"will_present_notification" forKey:@"_notificationType"]; + [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGING_NOTIFICATION_RECEIVED object:self userInfo:@{@"data": data, @"completionHandler": completionHandler}]; +} + ++ (void)didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(nonnull RCTNotificationResponseCallback)completionHandler +{ + NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: response.notification.request.content.userInfo]; + [data setValue:@"notification_response" forKey:@"_notificationType"]; + [data setValue:@YES forKey:@"opened_from_tray"]; + if (response.actionIdentifier) { + [data setValue:response.actionIdentifier forKey:@"_actionIdentifier"]; + } + [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGING_NOTIFICATION_RECEIVED object:self userInfo:@{@"data": data, @"completionHandler": completionHandler}]; +} + - (id)init { self = [super init]; if (self != nil) {