man*_*020 5 notifications push-notification firebase flutter firebase-cloud-messaging
我希望能够使用 Firebase Messaging 处理 iOS 和 Android 通知。
我遵循了一个教程,其中该人在 Android 上收到了以下格式的通知有效负载:
notification:{ title: "title" , body: "body" } }
Run Code Online (Sandbox Code Playgroud)
然而,在 iOS 上,我收到以下格式的有效负载:
aps:{ alert:{ title: "title" , body: "body" } }
Run Code Online (Sandbox Code Playgroud)
当配置如下所示的 Firebase 消息传递时,在 Flutter 中处理此问题的最佳方法是什么?
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['aps']['alert']['title']),
subtitle: Text(message['aps']['alert']['body']),
),
actions: <Widget>[
FlatButton(
child: Text("Dismiss"),
onPressed: () => Navigator.of(context).pop(),
)
],
),
);
},
Run Code Online (Sandbox Code Playgroud)
这些有效负载是可定制的还是我应该做类似的事情:
if (Platform.isIOS) {
...Text(message['aps']['alert']['title']),
} else {
...Text(message['notification']['title']),
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
937 次 |
| 最近记录: |