From 3c062182a51b08ef55ccccfb23d78b0d2241bc07 Mon Sep 17 00:00:00 2001 From: wontak Date: Mon, 1 Dec 2025 12:26:56 +0900 Subject: [PATCH 1/2] fix(messaging, ios): prioritize delegate call order in willPresentNotification --- .../RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m index e453851899..c45e2e2965 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m @@ -136,16 +136,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" body:notificationDict]; } - completionHandler(presentationOptions); } if (_originalDelegate != nil && originalDelegateRespondsTo.willPresentNotification) { [_originalDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; - } else { - completionHandler(presentationOptions); } + + // Don't consume completionHandler before the _originalDelegate has been processed + completionHandler(presentationOptions); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center From 4cee1d567e2e2583ce5f60a9132afee64bd4e19f Mon Sep 17 00:00:00 2001 From: wontak Date: Tue, 2 Dec 2025 10:49:33 +0900 Subject: [PATCH 2/2] chore: apply clang-formatting --- .../RNFBMessaging+UNUserNotificationCenter.m | 87 ++++++++++++------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m index c45e2e2965..de2b8cdae2 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m @@ -44,17 +44,24 @@ - (void)observe { __weak RNFBMessagingUNUserNotificationCenter *weakSelf = self; dispatch_once(&once, ^{ RNFBMessagingUNUserNotificationCenter *strongSelf = weakSelf; - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + UNUserNotificationCenter *center = + [UNUserNotificationCenter currentNotificationCenter]; if (center.delegate != nil) { _originalDelegate = center.delegate; - originalDelegateRespondsTo.openSettingsForNotification = (unsigned int)[_originalDelegate - respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)]; - originalDelegateRespondsTo.willPresentNotification = (unsigned int)[_originalDelegate - respondsToSelector:@selector(userNotificationCenter: - willPresentNotification:withCompletionHandler:)]; - originalDelegateRespondsTo.didReceiveNotificationResponse = (unsigned int)[_originalDelegate - respondsToSelector:@selector(userNotificationCenter: - didReceiveNotificationResponse:withCompletionHandler:)]; + originalDelegateRespondsTo.openSettingsForNotification = + (unsigned int)[_originalDelegate + respondsToSelector:@selector(userNotificationCenter: + openSettingsForNotification:)]; + originalDelegateRespondsTo.willPresentNotification = + (unsigned int)[_originalDelegate + respondsToSelector:@selector + (userNotificationCenter: + willPresentNotification:withCompletionHandler:)]; + originalDelegateRespondsTo.didReceiveNotificationResponse = + (unsigned int)[_originalDelegate + respondsToSelector:@selector + (userNotificationCenter: + didReceiveNotificationResponse:withCompletionHandler:)]; } center.delegate = strongSelf; }); @@ -82,12 +89,14 @@ - (NSNumber *)getDidOpenSettingsForNotification { - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler: - (void (^)(UNNotificationPresentationOptions options))completionHandler { - NSArray *presentationOptionsConfig = - [[RNFBJSON shared] getArrayValue:@"messaging_ios_foreground_presentation_options" - defaultValue:@[]]; + (void (^)(UNNotificationPresentationOptions options)) + completionHandler { + NSArray *presentationOptionsConfig = [[RNFBJSON shared] + getArrayValue:@"messaging_ios_foreground_presentation_options" + defaultValue:@[]]; - UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionNone; + UNNotificationPresentationOptions presentationOptions = + UNNotificationPresentationOptionNone; BOOL badge = [presentationOptionsConfig containsObject:@"badge"]; BOOL sound = [presentationOptionsConfig containsObject:@"sound"]; @@ -128,39 +137,47 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center } if (notification.request.content.userInfo[@"gcm.message_id"]) { - NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification]; + NSDictionary *notificationDict = + [RNFBMessagingSerializer notificationToDict:notification]; - // Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification - // will send the event for us, we don't want to duplicate them + // Don't send an event if contentAvailable is true - + // application:didReceiveRemoteNotification will send the event for us, we + // don't want to duplicate them if (!notificationDict[@"contentAvailable"]) { - [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" - body:notificationDict]; + [[RNFBRCTEventEmitter shared] + sendEventWithName:@"messaging_message_received" + body:notificationDict]; } } - if (_originalDelegate != nil && originalDelegateRespondsTo.willPresentNotification) { + if (_originalDelegate != nil && + originalDelegateRespondsTo.willPresentNotification) { [_originalDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; } - - // Don't consume completionHandler before the _originalDelegate has been processed + + // Don't consume completionHandler before the _originalDelegate has been + // processed completionHandler(presentationOptions); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { - NSDictionary *remoteNotification = response.notification.request.content.userInfo; + NSDictionary *remoteNotification = + response.notification.request.content.userInfo; if (remoteNotification[@"gcm.message_id"]) { - NSDictionary *notificationDict = - [RNFBMessagingSerializer remoteMessageUserInfoToDict:remoteNotification]; - [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" - body:notificationDict]; + NSDictionary *notificationDict = [RNFBMessagingSerializer + remoteMessageUserInfoToDict:remoteNotification]; + [[RNFBRCTEventEmitter shared] + sendEventWithName:@"messaging_notification_opened" + body:notificationDict]; _initialNotification = notificationDict; } - if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) { + if (_originalDelegate != nil && + originalDelegateRespondsTo.didReceiveNotificationResponse) { [_originalDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; @@ -171,12 +188,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification { - if (_originalDelegate != nil && originalDelegateRespondsTo.openSettingsForNotification) { - [_originalDelegate userNotificationCenter:center openSettingsForNotification:notification]; + if (_originalDelegate != nil && + originalDelegateRespondsTo.openSettingsForNotification) { + [_originalDelegate userNotificationCenter:center + openSettingsForNotification:notification]; } else { - NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification]; - [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_settings_for_notification_opened" - body:notificationDict]; + NSDictionary *notificationDict = + [RNFBMessagingSerializer notificationToDict:notification]; + [[RNFBRCTEventEmitter shared] + sendEventWithName:@"messaging_settings_for_notification_opened" + body:notificationDict]; _didOpenSettingsForNotification = YES; }