flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

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

Open russellwheatley opened this issue 1 year ago • 0 comments

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: https://github.com/firebase/flutterfire/issues/6517

Related Issues

fixes https://github.com/firebase/flutterfire/issues/4188 fixes https://github.com/firebase/flutterfire/issues/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.
  • [X] No, this is not a breaking change.

russellwheatley avatar Aug 08 '22 16:08 russellwheatley

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?

andreasgrossmann avatar Aug 16 '22 16:08 andreasgrossmann