我有一个后端服务器,可以将云消息推送到 iOS 和 Android 设备。在消息中,body_loc_key
属性设置为 someone_commented_moment
,body_loc_args
包含三个字符串参数。
Firebase 文档说明了 body_loc_key
:
On Android, use the key in the app's string resources when populating this value.
所以在 Android 上,我有一个包含此条目的 strings.xml:
<resources>
[...]
<string name="someone_commented_moment">
\@%1$s also commented on \@%2$s\'s moment: %3$s
</string>
[...]
</resources>
无论如何,此字符串资源永远不会加载到设备上显示的通知中。
在 iOS 上,这可以完美运行,而且我确实在 Intent 中获取了通知有效负载,该 Intent 从通知中启动了我的 Activity,因此我认为这不是服务器端的错误。我在这里错过了什么吗?我是否必须手动执行某些操作才能使这项工作正常进行,让 Firebase 找到并使用该字符串资源来本地化通知正文?
编辑: 触发通知的 python 代码如下所示:
self.fcm.notify_multiple_devices(registration_ids=push_tokens,
body_loc_args=notification.body_loc_args,
message_body=notification.type,
data_message=notification.data,
body_loc_key=notification.type,
sound="default")
其中self.fcm
是pyfcm.FCMNotification
类型的对象,notification.type
设置为"someone_commented_moment"
,正如打印语句以及发送到设备的内容所确认的那样。
最佳答案
好吧,我通过手动尝试对 FCM 服务器的不同请求找到了问题所在。如果还设置了“正常”消息正文,Android 似乎不会使用 body_loc_key
中的字符串资源 - 我们现在必须让服务器在推送到 Android 设备时省略消息正文.
关于android - Firebase 推送通知不使用来自 body_loc_key 的 Android 字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39319612/