Skip to content
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

feat(firebase_messaging): roadmap rework #4012

Merged
merged 40 commits into from
Nov 3, 2020
Merged

feat(firebase_messaging): roadmap rework #4012

merged 40 commits into from
Nov 3, 2020

Conversation

Salakar
Copy link
Member

@Salakar Salakar commented Nov 2, 2020


Co-authored-by: @Ehesp
Co-authored-by: @helenaford
Co-authored-by: @kirstywilliams
Co-authored-by: @Salakar



For anyone else coming across this PR with an issue or coming from a linked issue and want to discuss this upcoming version, please see the discussion post: #4023


A firebase_messaging dev release with these changes is available - 8.0.0-dev.3.


Description

The Firebase Messaging package has has a full overhaul as part of our roadmap (#2582). The package is now federated to allow integration with other platforms, along with upgrading underlying SDK versions. We've also added lots of features which can be seen below, however notably the biggest changes are:

  • Removed all manual native code changes that were originally required for integration - FlutterFire messaging now works out of the box once configured.
  • Support for MacOS. 💻
  • iOS background handler support 🥳
  • Android background handler debugging and logging support.
  • Reworked API for message handling (Streams + explicit handlers).
  • Fully typed Message & Notification classes (vs raw Maps).
  • New Apple notification permissions & support.
  • Lots of new documentation.

FirebaseMessaging

  • BREAKING: configure() has been removed in favor of calling specific static methods which return Streams.
    Why?: The previous implementation of configure() caused unintended side effects if called multiple times (either to register a different handler, or remove handlers). This change allows developers to be more explicit about registering handlers and removing them without effecting others via Streams.

  • DEPRECATED: Calling FirebaseMessaging() has been deprecated in favor of FirebaseMessaging.instance & FirebaseMessaging.instanceFor().

  • DEPRECATED: requestNotificationPermissions() has been deprecated in favor of requestPermission().

  • DEPRECATED: deleteInstanceID() has been deprecated in favor of deleteToken().

  • DEPRECATED: autoInitEnabled() has been deprecated in favor of isAutoInitEnabled.

  • NEW: Added support for isAutoInitEnabled as a synchronous getter.

  • NEW: Added support for getInitialMessage().
    This API has been added to detect whether a messaging containing a notification has caused the application to be opened via users interaction.

  • NEW: Added support for deleteToken().

  • NEW: Added support for getToken().

  • NEW: [Apple] Added support for getAPNSToken().

  • NEW: [Apple] Added support for getNotificationSettings(). See NotificationSettings below.

  • NEW: [Apple] Added support for requestPermission(). See NotificationSettings below.
    New permissions such as carPlay, crtiticalAlert, announcement are now supported.

  • NEW: [Android] Added support for sendMessage().
    The sendMessage() API enables support for sending FCM payloads back to a custom server from the device.

  • NEW - [Android] When receiving background messages on the separate background Dart executor whilst in debug, you should now see flutter logs and be able to debug/add breakpoints your Dart background message handler.

  • NEW: [Apple] Added support for setForegroundNotificationPresentationOptions().
    By default, iOS devices will not show notifications in the foreground. Use this API to override the defaults. See documentation for Android foreground notifications.

  • NEW - [Android] Firebase Cloud Messages that contain a notification are now always sent to Dart irregardless of whether the app was in the foreground or background. Previously, if a message came through that contained a notification whilst your app was in the foreground then FCM would not notify the plugin messaging service of the message (and subsequently your handlers in Dart) until the user interacted with it.

Event handling

Event handling has been reworked to provide a more intuitive API for developers. Foreground based events can how be accessed via Streams:

  • NEW: FirebaseMessaging.onMessage Returns a Stream that is called when an incoming FCM payload is received whilst the Flutter instance is in the foreground, containing a [RemoteMessage].
  • NEW: FirebaseMessaging.onMessageOpenedApp Returns a [Stream] that is called when a user presses a notification displayed via FCM. This replaces the previous onLaunch and onResume handlers.
  • NEW: FirebaseMessaging.onBackgroundMessage() Sets a background message handler to trigger when the app is in the background or terminated.

DEPRECATED: IosNotificationSettings

Usage of the IosNotificationSettings class is now deprecated (currently used with the now deprecated requestNotificationPermissions() method).

Instead of this class, use named arguments when calling requestPermission() and read the permissions back via NotificationSettings.

NEW NotificationSettings

The NotificationSettings class is returned from calls to requestPermission() and getNotificationSettings(). It contains information such as the authorization status, along with platform specific settings.

NEW: RemoteMessage

Incoming FCM payloads are now represented as a RemoteMessage rather than a raw Map.

NEW: RemoteNotification

When a message includes a notification payload, the results are returned as a RemoteNotification rather than a raw Map.

NEW:

BackgroundMessageHandler, AppleNotificationSetting, AppleShowPreviewSetting, AuthorizationStatus, AndroidNotificationPriority, AndroidNotificationVisibility

Additional types are available throughout messaging to aide with the latest changes.


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 (flutter 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 (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Related Issues

PRs

Ehesp and others added 18 commits July 30, 2020 13:38
Co-authored-by: ehesp <[email protected]>
Co-authored-by: Helena Ford <[email protected]>
Co-authored-by: Kirsty Williams <[email protected]>
Co-authored-by: Salakar <[email protected]>
@Salakar Salakar marked this pull request as ready for review November 3, 2020 18:00
@Salakar Salakar requested a review from kroikie as a code owner November 3, 2020 18:00
@Salakar Salakar changed the title feat(firebase_messaging): v1 rework feat(firebase_messaging): roadmap rework Nov 3, 2020
@Salakar Salakar merged commit a37c605 into firebase:master Nov 3, 2020
@joniaiuser

This comment has been minimized.

@Salakar

This comment has been minimized.

@Salakar
Copy link
Member Author

Salakar commented Nov 3, 2020


For anyone else coming across this PR with an issue or coming from a linked issue and want to discuss this upcoming version, please see the discussion post: #4023


@Ehesp Ehesp deleted the @invertase/messaging_v1 branch November 4, 2020 08:00
@swapnens
Copy link

swapnens commented Nov 9, 2020

Hi
I have an app that needs a video calling feature. I use firebase notification to start the call. In the previous version, I could not use the onBackgroundMessage handler to launch the app. The example app did not have any example of the same either. Can you please provide an idea of how we can launch the app on receiving notification (without user needing to press on it)?

@Ehesp
Copy link
Member

Ehesp commented Nov 9, 2020

@swapnens That's not possible, not with FCM at least. You could try hacking your way around by using some 3rd party library to force open an app in the background handler but no clue if that would work.

@swapnens
Copy link

swapnens commented Nov 9, 2020

@swapnens That's not possible, not with FCM at least. You could try hacking your way around by using some 3rd party library to force open an app in the background handler but no clue if that would work.

@Ehesp Could you give an idea about what can the onBackgroundMessage handler do?

@Ehesp
Copy link
Member

Ehesp commented Nov 9, 2020

You can call native on the background handler, so you could do something like trigger an app launch via an Intent (Android): https://stackoverflow.com/questions/3872063/how-to-launch-an-activity-from-another-application-in-android

That should work, however requires native code or using a 3rd party library. It's also not guaranteed trigger the background handler if the app is forced quit etc.

@firebase firebase locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.