简体   繁体   English

Flutter FirebaseMessaging onBackgroundMessage 替换文本

[英]Flutter FirebaseMessaging onBackgroundMessage replace text

I have a Flutter app that able to receive firebase notification when in background state.我有一个 Flutter 应用程序,它能够在后台 state 中接收 firebase 通知。 However I need to replace the text to be show when the background notification receive.但是,我需要替换收到背景通知时要显示的文本。

I not able to replace any text and not sure what is the correct way to do it.我无法替换任何文本,也不确定正确的方法是什么。

// setup the background incoming message
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

Future firebaseMessagingBackgroundHandler(RemoteMessage message) async {
return message.notification?.title?.replaceAll('key_word', 'KEYWORD');
}

For FCM: if that notification contains notification object along with data object and when app is in killed state that time that notification handles by system and it wil display that notification direct to the notification tray.对于 FCM:如果该通知包含通知 object 以及数据 object 并且当应用程序处于终止状态时 state 通知由系统处理的时间并将直接显示该通知到通知托盘。

in this case your backgroundlistener for notification will not be fired.在这种情况下,您的后台监听器将不会被触发。 if you want that to be fired then send only data messages in notifications.如果您希望触发它,则仅在通知中发送数据消息。

Please refer this doc: https://firebase.google.com/docs/cloud-messaging/concept-options请参考此文档: https://firebase.google.com/docs/cloud-messaging/concept-options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM