You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cloud-messaging/receive.md
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,3 +200,68 @@ Next, the worker must be registered. Within the entry file, **after** the `main.
200
200
201
201
Next restart your Flutter application. The worker will be registered and any background messages will be handled via this file.
202
202
203
+
### Handling Interaction
204
+
205
+
Since notifications are a visible cue, it is common for users to interact with them (by pressing). The default behavior on both Android & iOS is to open the
206
+
application. If the application is terminated it will be started, if it is in the background it will be brought to the foreground.
207
+
208
+
Depending on the content of a notification, you may wish to handle the users interaction when the application opens. For example, if a new chat message is sent via
209
+
a notification and the user presses it, you may want to open the specific conversation when the application opens.
210
+
211
+
The `firebase-messaging` package provides two ways to handle this interaction:
212
+
213
+
1.`getInitialMessage()`: If the application is opened from a terminated state a `Future` containing a `RemoteMessage` will be returned. Once consumed, the `RemoteMessage` will be removed.
214
+
2.`onMessageOpenedApp`: A `Stream` which posts a `RemoteMessage` when the application is opened from a background state.
215
+
216
+
It is recommended that both scenarios are handled to ensure a smooth UX for your users. The code example below outlines how this can be achieved:
/// Once you've completed platform specific requirements, follow these instructions:
27
+
/// 1. Install melos tool by running `flutter pub global activate melos`.
28
+
/// 2. Run `melos bootstrap` in FlutterFire project.
29
+
/// 3. In your terminal, root to ./packages/firebase_messaging/firebase_messaging/example directory.
30
+
/// 4. Run `flutterfire configure` in the example/ directory to setup your app with your Firebase project.
31
+
/// 5. Run the app on an actual device for iOS, android is fine to run on an emulator.
32
+
/// 6. Use the following script to send a message to your device: scripts/send-message.js. To run this script,
33
+
/// you will need nodejs installed on your computer. Then the following:
34
+
/// a. Download a service account key (JSON file) from your Firebase console, rename it to "google-services.json" and add to the example/scripts directory.
35
+
/// b. Ensure your device/emulator is running, and run the FirebaseMessaging example app using `flutter run --no-pub`.
36
+
/// c. Copy the token that is printed in the console and paste it here: https://github.com/firebase/flutterfire/blob/01b4d357e1/packages/firebase_messaging/firebase_messaging/example/lib/main.dart#L32
37
+
/// c. From your terminal, root to example/scripts directory & run `npm install`.
38
+
/// d. Run `npm run send-message` in the example/scripts directory and your app will receive messages in any state; foreground, background, terminated.
39
+
/// Note: Flutter API documentation for receiving messages: https://firebase.google.com/docs/cloud-messaging/flutter/receive
40
+
/// Note: If you find your messages have stopped arriving, it is extremely likely they are being throttled by the platform. iOS in particular
41
+
/// are aggressive with their throttling policy.
42
+
///
43
+
/// To verify that your messages are being received, you ought to see a notification appearon your device/emulator via the flutter_local_notifications plugin.
21
44
/// Define a top-level named handler which background/terminated messages will
22
45
/// call.
23
-
///
24
-
/// To verify things are working, check out the native platform logs.
0 commit comments