FCM rich push notification payload for iOS
M

2

22

I am using FCM for my project. It's have rich push notification for a type. I tried to modified most of possible ways to get push from FCM. I got obly ordinary push from FCM, not with image.

I am also check with APNS same coding using push try. I got what expected design for push notification.

Here my APNS payload

{
  "aps": {
     "alert": "Enter your message",
     "badge": 1,
     "sound": "default",
     "content-available": 1,
     "mutable-content": 1
  },
  "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
}

Here FCM payload

{
   "to": "dWB537Nz1GA:APA91bHIjJ5....",
   "data":
   {
      "message": "Offer!",
      "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
   },
   "notification":
   {
      "body": "Enter your message",
      "sound": "default",
      "content-available": 1,
      "mutable-content": 1
   }
}

Also I am need category more details about payload in FCM

Am I missing any setting in fire-base console or is that from payload.

Merganser answered 1/3, 2017 at 12:27 Comment(0)
Z
47

The mutable-content and content-available in your FCM payload is incorrect. It should be formatted as mutable_content and content_available. Both are boolean and must also be outside the notification parameter. Like so:

{
   "to": "dWB537Nz1GA:APA91bHIjJ5....",
   "content_available": true,
   "mutable_content": true,
   "data":
   {
      "message": "Offer!",
      "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
   },
   "notification":
   {
      "body": "Enter your message",
      "sound": "default"
   }
}

For the counterpart of category in FCM, you should use click_action:

The action associated with a user click on the notification.

Corresponds to category in the APNs payload.

Z answered 1/3, 2017 at 13:46 Comment(8)
@Z Is this the right FCM payload? I mean why message and body are separated? Can't it be both in notification or both in data ? It feels not right to me to have the title and message of the notification in a separated { }Electrocorticogram
@Balanced Its a valid payload. However, what you did mention is also valid. It all deoends on your use-case.Z
can we pass dictionary in payload ? "to" : “device token”, "content_available": true, "notification" : { }, "data": { "payload" : { "dataa": { "btn_action": “Some text“, "lock_mac" : "0Some text", "device_type" : "iOS", “some key” : "Some text" } } } }Loud
@Loud The data message payload caters to custom data. So yes. Just makw sure you handle it properly. Cheers!Z
AL. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) userInfo["payload"] as? [String:Any] is always nil in the above functionLoud
@Loud I would suggest posting a question with the corresponding codes and details so that the community could help you better. :)Z
Is this "mutable-content" to "mutable_content" mapping documented anywhere? I'm not finding it.Heavily
@Heavily firebase.google.com/docs/cloud-messaging/…Z
B
8

This worked for me. The accepted answer seems to have some unnecessary information.

{
  "to" : "devicekey OR /topics/sometopic",
  "mutable_content": true,
  "data": {
    "mymediavideo": "https://myserver.com/myvideo.mp4"
  },
  "notification": {
    "title": "my title",
    "subtitle": "my subtitle",
    "body": "some body"
  }
}
Bottrop answered 23/5, 2018 at 9:59 Comment(2)
Please ask the author of the accepted answer to improve his answer with this information.Virginiavirginie
Check this commentMerganser

© 2022 - 2024 — McMap. All rights reserved.