Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Payload for Rich Text Notification using FCM

I am implementing Rich Text Notification in one of my app. I know that I need the payload in the following format:

{
  "aps": {
      "alert": {
          "title": "", 
          "body": “”
      },
      "badge": 1,
      "sound": "default",
      "mutable-content": true,
      "content-available": true,
      "category": "defaultCategory"
  },
  "image_url": ""
}

Although when I tried with default APNS process I did it successfully, but I just faced a issue while implementing it using FCM, and problem is that I am not receiving the keys:

mutable-content: 1
category: defaultCategory

I explored about it and found a url FCM rich push notification payload for iOS , I tried with the mentioned keys as well.

"mutable_content": true,
"click_action": defaultCategory,

But even using these I am not getting correct result. Current payload I am receiving after final changes are:

{
    gcm.notification.category: defaultCategory, 
    image: /r/u/rustyredsmall.jpg, 
    type_id: XMH677878912-L-Blue, 
    type: Product, 
    aps: {
        alert =     {
           body = "new product notification message2018-05-24 00:00:00";
           title = "Product Notification";
        };
       badge = 1;
       sound = default;
    }, 
    0: {"mutable_content":true}, 
    gcm.message_id: 0:1527142412430945%98b85c5198b85c51
}

Any suggestion, how I can get the correct payload?

like image 827
Ankit Jayaswal Avatar asked May 24 '18 09:05

Ankit Jayaswal


1 Answers

I debugged the issue and resolved the issue successfully, there are some problem with the key placement at sever end. We have created the payload at server end as:

{
    "to”: “xyz”,
    "mutable_content": true,
    "notification":
        {
            "body": “this is the message body.“,
            "title": “tiltle text”,
            "sound": "default",
            "badge": 1,
            "click_action": "defaultCategory"
        },
    "data":
        {
            "type": "Category",
            "typeId": "74",
            "redirect_title": "",
            "image_url": "\/d\/r\/dress_16.jpg",
            "notification_id": "1"
        }
}

FCM formatted this payload and sent it to mobile end in the following format:

{
    gcm.message_id: “0:1527233474081223%98b85c5198b85c51”, 
    aps: {
        alert: {
            body: "new product notification message2018-05-24 00:00:00";
            title: "Product Notification";
        };
        badge: 1;
        category: “defaultCategory”;
        mutable-content: 1;
        sound: “default”;
    }, 
    notification_id: 11, 
    typeId: “XMH677878912-L-Blue”, 
    image_url: “/r/u/rustyredsmall.jpg”, 
    type: “Product”, 
    redirect_title: “Midi Dress-L-Blue”
}
like image 72
Ankit Jayaswal Avatar answered Nov 01 '22 16:11

Ankit Jayaswal