Skip to content

fix(messaging, ios): prioritize delegate call order in willPresentNotification - #8786

Merged
mikehardy merged 2 commits into
invertase:mainfrom
WontakKim:fix/ios-messaging-custom-completion-handler-support
Jan 29, 2026
Merged

mikehardy merged 2 commits into
invertase:mainfrom
WontakKim:fix/ios-messaging-custom-completion-handler-support

Conversation

@WontakKim

@WontakKim WontakKim commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue where completionHandler in userNotificationCenter:willPresentNotification:withCompletionHandler: is called before the original delegate, preventing custom foreground notification presentation logic from working.

Related issues

Release Summary

Fixed iOS messaging to respect custom notification presentation logic by calling the original delegate before consuming the completionHandler.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
    • Other (macOS, web)
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

Tested Scenario:

  1. Implemented custom willPresentNotification handler in AppDelegate to control notification presentation
  2. Sent FCM notification while app is in foreground
  3. Verified custom logic is now executed and controls notification display behavior

Before Fix:

  • Custom completion handler in AppDelegate was ignored
  • Notifications always displayed with library's default options

After Fix:

  • Custom completion handler in AppDelegate is respected
  • Developers can control whether/how to display foreground notifications
  • Default behavior preserved when no custom delegate exists

Code Example Tested:

// AppDelegate.m
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  // Custom logic to determine notification presentation
  if (shouldShowNotification) {
    completionHandler(UNNotificationPresentationOptionBanner | 
                     UNNotificationPresentationOptionSound);
  } else {
    completionHandler(UNNotificationPresentationOptionNone);
  }
}

@vercel

vercel Bot commented Dec 1, 2025

Copy link
Copy Markdown

@wrtn-wontak is attempting to deploy a commit to the Invertase Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Dec 1, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@WontakKim WontakKim changed the title fix(messaging, ios): prioritize delegate call order in willPresentNot… fix(messaging, ios): prioritize delegate call order in willPresentNotification Dec 1, 2025
@MichaelVerdon

MichaelVerdon commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Hi there @WontakKim looks good to me just fix the linter issues please and I will approve it and ensure the CLA is signed.

@WontakKim

WontakKim commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Hi @MichaelVerdon, I've signed the CLA docs and ran clang-format -i packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m. It seems to have changed some unnecessary lines. Could you please review my changes again?

@mikehardy
mikehardy force-pushed the main branch 4 times, most recently from 38a52cd to 7af280b Compare December 8, 2025 20:10
@WontakKim

Copy link
Copy Markdown
Contributor Author

Hi @MichaelVerdon , kindly reminds you to review this PR. Thanks.

@github-actions

Copy link
Copy Markdown
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it.

If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing!

You have 15 days until this gets closed automatically

@github-actions github-actions Bot added Stale and removed Stale labels Jan 12, 2026
@WontakKim

Copy link
Copy Markdown
Contributor Author

Hi @MichaelVerdon , It's been a while since I left my last comment, but I haven't received any response yet. Could you please check on this?

@MichaelVerdon

Copy link
Copy Markdown
Contributor

Hi @MichaelVerdon , It's been a while since I left my last comment, but I haven't received any response yet. Could you please check on this?

Hi there apologies, I got caught up in alot of other work. I am looking now, thank you for your patience

@MichaelVerdon

Copy link
Copy Markdown
Contributor

This looks good to me hapy to approve after CI runs on this one. Have you signed the CLA?

@WontakKim

Copy link
Copy Markdown
Contributor Author

Hi, yes I have signed CLA.

@mikehardy

Copy link
Copy Markdown
Collaborator

Hi @WontakKim - the CLA bot doesn't seem to be registering the agreement - the typical cause of this is misaligned email address in github vs the commit. I see wontak-wtrn as the commit author but on this PR you are @WontakKim - so the CLA is not associating the author of the commit with the signer of the CLA.

https://github.com/cla-assistant/cla-assistant/blob/main/COMMON_ISSUES.md#you-are-not-able-to-sign-a-cla

You'll need to choose and either make sure the email address you configured in git for your commits is added to your github account or that you rewrite the commits and repush them after you reconfigure git to be the same email you use for your github account

@mikehardy mikehardy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me (thank you!) pending resolution of CLA signing issue

@mikehardy

Copy link
Copy Markdown
Collaborator

I am closing and reopening just to re-trigger CI checks, despite being an admin in the repo github CI is stuck for this PR

@mikehardy mikehardy closed this Jan 26, 2026
@mikehardy mikehardy reopened this Jan 26, 2026
@wontak-wrtn

Copy link
Copy Markdown

I resigned CLA. @mikehardy thanks for guiding me.

@mikehardy
mikehardy force-pushed the fix/ios-messaging-custom-completion-handler-support branch from 4cee1d5 to f2eae6c Compare January 27, 2026 02:51
@mikehardy

Copy link
Copy Markdown
Collaborator

android check failure was a flake, it passed on rerun but there was still a problem with ios for some reason
I pulled the PR locally and ran yarn lint:ios:fix, squashed that into the second commit, and pushed those back out to the branch

CI should re-run then ideally this is good to go, I'll check it in the morning

@mikehardy
mikehardy merged commit d6f403a into invertase:main Jan 29, 2026
19 of 22 checks passed
olerass added a commit to rainbow-me/rainbow that referenced this pull request Apr 27, 2026
After bumping `@react-native-firebase/*` from 20.1.0 to 23.8.8 in #7319 (Apr 2026), iOS users see both a system banner AND a notifee-displayed local notification when a push arrives while the app is foregrounded. Pre-bump behavior was the notifee notification only.

The cause is upstream: invertase/react-native-firebase#8786 (merged Feb 2026, shipped in v23.8.5) reordered RNFB's iOS `willPresent` delegate so the original AppDelegate handler is called first. Previously, RNFB consumed the one-shot `completionHandler` with its own default options (empty, since we don't have a `firebase.json`) before forwarding to AppDelegate, making AppDelegate's `completionHandler([.sound, .badge, .list, .banner])` a no-op. With the new order, AppDelegate wins and iOS now honors the full `[.sound, .badge, .list, .banner]` set the handler has been quietly asking for since #6607 (Aug 2025).

This change updates AppDelegate's `willPresent` to call `completionHandler([])`, which suppresses all iOS-side presentation for the FCM remote when foregrounded. Rainbow's user-visible foreground notification UI is rendered by notifee from the separate `onMessage` JS handler (`src/notifications/foregroundHandler.ts` → `notifee.displayNotification`). Letting iOS also present the FCM payload would duplicate Notification Center entries and add badge increments that pre-bump prod never had. Returning `[]` matches the pre-RNFB-23.8.5 default of `UNNotificationPresentationOptionNone`. Background and killed-app notifications are unaffected since this delegate only runs in the foreground case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛] FirebaseMessaging(iOS): completionHandler called before originalDelegate in willPresentNotification

5 participants