【发布时间】:2020-06-19 12:36:19
【问题描述】:
我已经在我的颤振应用程序中使用 firebase_messaging 插件实现了 Firebase 云消息传递,但有些东西我不明白。 我在函数中有这个有效负载,可以在创建的消息上发送推送通知:
var payload = {
notification: {
title: 'Nuevo mensaje!',
body: `${sender} te ha dejado mensaje ${fecha}`,
icon: 'https://*************.es/wp-content/uploads/2019/11/**************.png',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
},
};
在我尝试以这种方式获取标题和正文之前,一切都很好:
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
它们是空的,所以我查看了消息,发现我收到的是这样的:
{gcm.message_id: dsadsadasd, google.c.sender.id: dasdsaddcwfewf3, google.c.a.e: 1, aps: {alert: {title:Nuevo mensaje!, body: 罗纳尔多 te ha dejado mensaje:7 3 2020 15:00},类别: FLUTTER_NOTIFICATION_CLICK}}
所以改变我解码消息的方式:
content: ListTile(
title: Text(message['aps']['alert']['title']),
subtitle: Text(message['aps']['alert']['body']),
),
一切正常,但我想知道为什么我发送“通知:{title:}”但收到 aps:{alert:{title:}}。我遵循的教程似乎可以通过“通知”键正常接收。这里发生了什么?我错过了什么?代码有效,但我觉得我没有以正确的方式实现它。
编辑:我刚刚在 Android 上对其进行了测试,它在那里解码了它应该做的方式:
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']
所以现在我像 Platform.isAndroid 一样处理它?消息:消息; 但我想知道发生了什么。
【问题讨论】:
标签: node.js flutter firebase-cloud-messaging