【发布时间】:2021-08-09 23:41:34
【问题描述】:
我想在我的应用处于后台时显示推送通知。
我正在使用flutter_local_notifications 包和firebase_messaging 包。
推送通知与 firebase_messaging 以及当我的应用程序是后台时效果很好。
但是,下面的方法:
// The following handler is called, when App is in the background.
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
如果 RemoteNotification 对象通过 RemoteMessage 传递,则不会调用:
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('message from background handler');
print("Handling a background message: ${message.messageId}");
// If this is null, then this handler method is called
RemoteNotification remoteNotification = message.notification;
showNotificationFromData(message.data);
}
因此,我必须传递message.data 对象,它是Map<String, dynamic>。
我的问题是,当调用此 firebaseMessagingBackgroundHandler 处理程序方法时,我不再收到推送通知。
所以我一直在尝试使用flutter_local_notification 包来显示推送通知,但正如它所说,它是“本地的”,所以它在前台工作正常,但显然不在后台(相同的代码,与相同的数据不会在后台显示为推送通知)。
问题:
我需要调用firebaseMessagingBackgroundHandler 处理程序来处理我的应用程序中的事件。所以当我的应用程序在后台时,我可以做些什么来推送通知?
谢谢
【问题讨论】:
标签: flutter dart firebase-cloud-messaging flutter-notification