问题描述
我正在尝试使用 firebase_messaging 来在抖动中显示本地化通知,我正在获取带有3的json通知正文中的语言字符串,如下所示:
I am trying to display localized notification in flutter using firebase_messaging, I am getting a json with 3 language strings in body of a notification like so:
{"it": "italian text", "de": "german text", "en": "english text"}
截至目前,它在通知托盘中显示了整个json字符串.当应用程序在后台运行时,如何从json中选择适当的语言文本并显示在通知中?myBackgroundMessageHandler永远不会调用此函数.谢谢.
As of now, it is showing the whole json string in the notification tray. How can I select the appropriate language text from the json and show in notification when app is in background? myBackgroundMessageHandler this function is never called. Thanks.
推荐答案
在后台时,我无法调用myBackgroundMessageHandler函数.我确实找到了几种使用loc_key本地化通知的方法,例如iOS中的 this 和Android中的此.
I could not get myBackgroundMessageHandler function to call when in background. I did find a couple of ways to localize notifications using loc_key like tags in iOS like this and in android like this.
但是,此方法不适用于我的情况,因为我必须在通知中发送大量文本(例如,用于发送促销).因此,当用户订阅某些内容时,我最终将设备的语言保存在后端中.这样,后端可以仅以该语言将通知发送到该设备.
However, this method was not suitable for my case because I had to send a bulk text (for example for sending promotions) in the notification. So I ended up saving the device's language in the backend when user subscribes something. That way backend can send the notification only in that language to that device.
这篇关于Flutter-如何在后台格式化通知的标题和正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!