简体   繁体   中英

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. I need to use DataMessage for send custom key value pair to both OS, and my data message is something like:

{
  "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. IOS receive data only when app is in foreground. What's wrong?

I was pulling my hair out for the same thing, trying to make it work on both Android and 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.

In iOS, if you send notification payload, then it works in background, but data payload won't work in background. See this issue for more info

Seems like you have to sacrifice one platform for other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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