diff --git a/docs/messaging/notifications.mdx b/docs/messaging/notifications.mdx index 1d76291dbe..b2bab82188 100644 --- a/docs/messaging/notifications.mdx +++ b/docs/messaging/notifications.mdx @@ -107,6 +107,10 @@ could open a specific screen for example). The API provides two APIs for handlin - `getInitialNotification`: When the application is opened from a quit state. - `onNotificationOpenedApp`: When the application is running, but in the background. +These fire for the **default notification open** (user taps the notification body). They do **not** fire for +custom notification-category actions or dismiss; those interactions need a dedicated response API (tracked +internally — do not route custom-action navigation through opened/initial). + To handle both scenarios, the code can be executed during setup. For example, using [React Navigation](https://reactnavigation.org/) we can set an initial route when the app is opened from a quit state, and push to a new screen when the app is in a background state: diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m index 4e98d2f176..cf9301ebbc 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m @@ -152,7 +152,8 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { NSDictionary *remoteNotification = response.notification.request.content.userInfo; - if (remoteNotification[@"gcm.message_id"]) { + if ([[response actionIdentifier] isEqualToString:UNNotificationDefaultActionIdentifier] && + remoteNotification[@"gcm.message_id"]) { NSDictionary *notificationDict = [RNFBMessagingSerializer remoteMessageUserInfoToDict:remoteNotification]; [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" @@ -160,10 +161,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center _initialNotification = notificationDict; } - if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) { - [_originalDelegate userNotificationCenter:center - didReceiveNotificationResponse:response - withCompletionHandler:completionHandler]; + // _originalDelegate is weak — capture strong local before nil-check + message + // (same race as willPresent; otherwise completionHandler may never run). + id strongOriginalDelegate = _originalDelegate; + if (strongOriginalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) { + [strongOriginalDelegate userNotificationCenter:center + didReceiveNotificationResponse:response + withCompletionHandler:completionHandler]; } else { completionHandler(); } @@ -171,8 +175,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification { - if (_originalDelegate != nil && originalDelegateRespondsTo.openSettingsForNotification) { - [_originalDelegate userNotificationCenter:center openSettingsForNotification:notification]; + id strongOriginalDelegate = _originalDelegate; + if (strongOriginalDelegate != nil && originalDelegateRespondsTo.openSettingsForNotification) { + [strongOriginalDelegate userNotificationCenter:center openSettingsForNotification:notification]; } else { NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification]; [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_settings_for_notification_opened"