Skip to content

fix(firebase_messaging, iOS): ensure initial notification was tapped to open app. fixes getInitialMessage() & onMessageOpenedApp() . #9315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 10, 2022

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Aug 8, 2022

Description

This fixes the scenario where a push notification is sent but the user presses the app icon to open app. This PR ensures that the notification that was tapped to open the app is the RemoteMessage from getInitialMessage().

This also fixes onMessageOpenedApp which was opening the app when tapping a notification from a terminated state.

I've also discovered that when the app is in a terminated state and a push notification is sent, the initState() and build() functions within the Flutter application are called before the app has been opened. Therefore, the getInitialMessage() cannot be put intoinitState(). Otherwise, the RemoteMessage returned from getInitialMessage() will be null as it is not known whether the app was opened via notification yet.

This bug is being tracked here: #6517

Related Issues

fixes #4188
fixes #8979

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley russellwheatley changed the title fix(firebase_messaging, iOS): ensure initial notification was tapped to open app. fixes getInitialMessage(). fix(firebase_messaging, iOS): ensure initial notification was tapped to open app. fixes getInitialMessage() & onMessageOpenedApp() . Aug 8, 2022
…FirebaseMessagingPlugin.m

Co-authored-by: Mike Diarmid <[email protected]>
@russellwheatley russellwheatley merged commit e66c59c into master Aug 10, 2022
@russellwheatley russellwheatley deleted the @russell/messaging-4188 branch August 10, 2022 12:48
@catelbow
Copy link

Is it possible for Firebase Messaging to also remove the notification from Android's system tray if the user ignores the push notification but presses the app icon to open the app as described in #4516 or should a plugin such as Eraser be used?

erdemyerebasmaz added a commit to breez/breezmobile that referenced this pull request Aug 16, 2022
anytime:
- bottomPadding of view is added into consideration when placing Up Next bottom sheet and snackbar notifications
- Bug fixes: URL launches now call external app rather than webview; fix position slider on iOS; fix now playing restart bug on queue; fix OPML export label on English.

firebase_messaging:
- FIX: ensure initial notification was tapped to open app. fixes getInitialMessage() & onMessageOpenedApp() . ([#9315](firebase/flutterfire#9315)).  ([e66c59ca](firebase/flutterfire@e66c59c))
@firebase firebase locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: messaging type: bug Something isn't working
Projects
None yet
4 participants