[英]Fcm: Send DataMessage to Android and IOS when app is in background and in foreground
I'm implementing my custom FCM server for send notification to Android and IOS devices.我正在实现我的自定义 FCM 服务器,用于向 Android 和 IOS 设备发送通知。 I need to use DataMessage for send custom key value pair to both OS, and my data message is something like:
我需要使用 DataMessage 向两个操作系统发送自定义键值对,我的数据消息类似于:
{
"content_available": true,
"data": {
"lan": "IT",
"messageId": "67",
"message": "test message"
},
"registration_ids": [
"..."
],
"priority": "high"
}
Android receive correctly notification when app is in foreground and in background.当应用程序在前台和后台时,Android 会正确收到通知。 IOS receive data only when app is in foreground.
IOS 仅在应用程序处于前台时接收数据。 What's wrong?
怎么了?
I was pulling my hair out for the same thing, trying to make it work on both Android and iOS.我正在为同样的事情拉我的头发,试图让它在 Android 和 iOS 上都能运行。 Turns out you can't.
事实证明你不能。
In Android, if it's data payload, it will works in background, and notification payload won't work in background.在Android中,如果是数据载荷,它会在后台工作,而通知载荷不会在后台工作。
In iOS, if you send notification payload, then it works in background, but data payload won't work in background.在 iOS 中,如果您发送通知有效负载,则它会在后台运行,但数据负载将不会在后台运行。 See this issue for more info
有关更多信息,请参阅此问题
Seems like you have to sacrifice one platform for other.似乎您必须为另一个平台牺牲一个平台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.