我的 index.ts 中有以下代码
const payload: admin.messaging.MessagingPayload = {
notification: {
title: 'New Order!',
body: you sold a ${order.day} for ${order.time},
},
};
return fcm.sendToDevice(tokens, payload);
这在我的 Flutter 中:
messaging.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");
},
onBackgroundMessage: myBackgroundMessageHandler
);
}
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
var data = message['data'] ?? message;
print(data);
// Or do other work.
}
虽然 onMessage
部分运行良好,但 onLaunch 和 onResume 不起作用。 Netierh 负责 onBackgroundMessage。
答案 0 :(得分:0)
您可以使用 if
方法和 onBackgroundMessage
包 https://pub.dev/packages/flutter_local_notifications
您正在检查数据而不是通知
flutter_local_notifications