Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/messaging/notifications.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,32 @@ - (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"
body:notificationDict];
_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<UNUserNotificationCenterDelegate> strongOriginalDelegate = _originalDelegate;
if (strongOriginalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) {
[strongOriginalDelegate userNotificationCenter:center
didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
} else {
completionHandler();
}
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
openSettingsForNotification:(nullable UNNotification *)notification {
if (_originalDelegate != nil && originalDelegateRespondsTo.openSettingsForNotification) {
[_originalDelegate userNotificationCenter:center openSettingsForNotification:notification];
id<UNUserNotificationCenterDelegate> 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"
Expand Down
Loading