Closed JacobFrericks closed 3 years ago
I am having the same issue
I am having the same issue
You should add your title and body in data like below:
{
"registration_ids": [
],
"notification": {
"title": "Hello Notification API",
"body": "Send From Notification API"
},
"priority": "high",
"data": {
"click_action" : "FLUTTER_NOTIFICATION_CLICK",
"title": "Hello Notification API",
"body": "Send From Notification API",
}
}
@ManKeomorakort I'm aware that I can push the title and body through via data, but doesn't that negate the reason for having the "title" and "text" options available in Step 1 of the Firebase console? Why even have these as options if they don't work?
I believe this is a bug that requires fixing for Flutter, and using the custom data in Step 5 with the keys "title" and "body" is just a workaround.
I confirm this used to work a couple of months ago; it is definitely a bug somewhere. Adding title
and body
to data
is a workaround not a solution.
Hi @JacobFrericks
could you please provide your pubspec.yaml
Thank you
@iapicca You can see the file you requested in my sandbox repository mentioned in the first comment. See https://github.com/JacobFrericks/sandbox/tree/master/pubspec.yaml
Hi @JacobFrericks I missed that thanks
So what's the next step for this? Is there any testing that I can do? It's been almost two weeks, just wanted to get an update.
I ran into the same issue as well. This is very frustrating as we need to do further processing of the notification in our app.
It's hard to believe this has been reported 6 weeks ago and is very easy to reproduce, but hasn't been fixed yet. This breaks every app that actually wants to do anything with the contents of a notification.
I also encountered the same issue:
send notification from cloud: receive message: onMessage: OK onLaunch: NG onResume: NG
I tried:
Actually, I still think that my code is in error, but I could not find the error anywhere.
NotificationService :
class NotificationService extends BaseGateway {
WorkspaceGateway _workspaceGateway;
FirebaseMessaging _firebaseMessaging;
static final NotificationService _singleton = NotificationService._internal();
NotificationService._internal();
factory NotificationService({WorkspaceGateway wsGateway}) {
_singleton._workspaceGateway = wsGateway;
return _singleton;
}
Future registerNotifyDevice() async {
if (_firebaseMessaging == null) {
_firebaseMessaging = FirebaseMessaging();
}
final prefs = await SharedPreferences.getInstance();
String firebaseToken = prefs.getString(XFirebase.token);
String registeredAtString = prefs.getString(XFirebase.registeredAt);
DateTime registeredAt;
if (registeredAtString != null && registeredAtString.isNotEmpty) {
print('stored registered at time $registeredAtString');
registeredAt = DateTime.parse(registeredAtString);
}
if (firebaseToken != null &&
firebaseToken.isNotEmpty &&
registeredAt != null &&
DateTime
.now()
.difference(registeredAt)
.inDays <= 3) {
print("firebase has registered");
return;
}
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging
.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
firebaseToken = await _firebaseMessaging.getToken();
if (firebaseToken != null && firebaseToken.isNotEmpty) {
_registerNotifyDevice(firebaseToken);
}
}
.
.
.
pubspec.yaml
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: ^0.12.0
flutter_webview_plugin: ^0.3.10+1
shared_preferences: ^0.5.3+5
flutter_secure_storage: ^3.3.1+1
provider: ^4.0.1
timeago: ^2.0.21
intl: ^0.16.0
web_socket_channel: ^1.1.0
multi_image_picker: ^4.6.3
uuid: 2.0.4
sentry: ">=3.0.0 <4.0.0"
http_extensions_log: ^0.1.2
device_info: ^0.4.2+1
#Fab menu
flutter_speed_dial: ^1.2.5
firebase_messaging: ^6.0.13
flutter_local_notifications: ^1.4.1
fluttertoast: ^3.1.3
flutter_svg: ^0.15.0
cached_network_image: ^2.0.0
#text editor
extended_text_field: ^0.4.9
extended_text: any
connectivity: ^0.4.8+1
photo_view: ^0.9.1
package_info: ^0.4.0+13
url_launcher: ^5.4.1
google_fonts: ^0.3.9
can anyone help me, please :)
@hungbu when you say that it "works normally" are you getting the title/body for onResume/onLaunch? I just updated flutter for the stable, then dev, then master channels, all with the same results as the first post: title/body are appearing in onMessage, but not onResume/onLaunch.
As for your question, I would recommend making a new issue.
I also updated to the latest firebase_core and firebase_messaging with the same result.
firebase_core: ^0.4.4+3 firebase_messaging: ^6.0.13
So, I got tired of waiting for this fix to be prioritized/fixed, and created a workaround. I pushed it to my sandbox repo. Here's the code changes I performed to create the workaround (it should be a simple copy/paste for most people): https://github.com/JacobFrericks/sandbox/commit/398d1763cfb195a1f68a6f2ed9b8b8b281b9e606
Below is the code in case the link gets broken somewhere down the line:
Map<String, dynamic> fixMessageTitleAndBody(Map<String, dynamic> message) {
if (!message.containsKey("notification")) {
message["notification"] = {};
}
if (!message["notification"].containsKey("title") && message["data"].containsKey("title")) {
message["notification"]["title"] = message["data"]["title"];
}
if (!message["notification"].containsKey("body") && message["data"].containsKey("body")) {
message["notification"]["body"] = message["data"]["body"];
}
return message;
}
onResume: (Map<String, dynamic> message) async {
// WORKAROUND
message = fixMessageTitleAndBody(message);
print("onResume: $message");
},
This workaround requires two additional data fields to be sent from the console: "title" and "body". The workaround moves these two fields from the data section of the message to the notification (as if the message had them all along).
The advantage of this workaround is it won't require any code changes when Flutter fixes this issue. You simply need to provide the title and body in the flutter console as normal, and the workaround method do nothing.
@JacobFrericks even I am tired.... Workarounds, Workarounds, Workarounds... Thanks for the help
I am having the same issue using firebase_messaging: ^6.0.13
I have the same issue in firebase_messaging: ^7.0.0
but it is very interesting to note that the title and body does appear in the notification that appears when the app is in background or terminated, but when I print the message in my onResume and onLaunch callbacks, the notification key is an empty map.
I have this problem for iOs but it works fine on Android.
This is still happening when using firebase_messaging: ^7.0.3
(Android 11, Pixel 3a).
Could someone take a look at this? It has been labeled with severe: regression
for more than half a year now.
I have the same error on Android using firebase_messaging: ^7.0.3.
This issue still happening with flutter on firebase_messaging: ^7.0.3. alternatively can use message Custom data to send the same data
I have the same problem. I could not get the title and body when notification is send from firebase console. onMessage there is no problem but onResume and onLaunch notification is empty like ''{notification: {}, data: {collapse_key: com.exaple.vedat, google.original_priority: high, google.sent_time: 1603976954143, google.delivered_priority: high, google.ttl: 2419200, from: 117431216057, click_action: FLUTTER_NOTIFICATION_CLICK, google.message_id: 0:1603976954318920%8a5620e18a5620e1}}" Before it is printed on the console Δ± had a message like this; W/FirebaseMessaging( 2431): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
I have this problem for iOs but it works fine on Android.
Because all things should be balanced, I have the same problem on Android but not on iOS.
I have the same problem but now it doesen't even work with onMessage(). What am I doing wrong?
Problem is still present (at least on Android 10) with version 7.0.3
π
Hey @JacobFrericks, we're now on version 9 and the onResume
& onLaunch
handlers do not exist anymore. I'm going to close this, but if you come across any other problems, please feel free to create a new issue.
Describe the bug The callbacks are set to print the message when it's received. When I send a notification to my app from the firebase console, I correctly get a title and body for onMessage, but onResume, I get an empty object under the Notification parent (see below for an example of what I see)
To Reproduce Steps to reproduce the behavior:
Follow the instructions for adding firebase to your app: https://firebase.google.com/docs/flutter/setup?platform=android (NOTE: I have added two packages firebase_core: ^0.4.4 and firebase_messaging: ^6.0.9 Copy and paste the example into main.dart. Example is found here: https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/example/lib/main.dart Start the app in either a simulator or a real device, and copy the token printed in the terminal. Keep the application open. NOTE: I have also published this code in a repository. If you want to skip steps 1-2, you can clone it here: https://github.com/JacobFrericks/sandbox
// OnMessage
// OnResume
// OnLaunch
Expected behavior The expected behavior is that when the notification is received, onResume/onLaunch messages should contain both a title and body under the notification parent. Instead, an empty notification object appears.
Flutter Doctor: