I'm using firebase in my react-native project (with typescript), I set up all thing correctly and it works fine with data
messages like below:
{
"to": "fcm-token",
"data": {
"field1": "value1",
"field2": "value1",
"field3": "value1"
}
}
in my App, I can access my data using data
filed of RemoteMessage
like below:
const data: MyDataType = remoteMessage.data;
const {/* destructed fields */} = data;
But when my server send nested Object to FCM server, it converts them to string and so I can not access them directly like above.
this is what my server send to FCM server:
{
"to": "fcm-token",
"data": {
"field1": {
"subfield1": "subvalue1",
"subfield2": "subvalue2",
},
"field2": "value1",
"field3": "value1"
}
}
and this is what I get in my application:
{
"to": "fcm-token",
"data": {
"field1": "{"subfield1": "subvalue1","subfield2": "subvalue2"}", <--- the problem is here, it must be a nested object not string
"field2": "value1",
"field3": "value1"
}
}
I set Content-Type
header to application/json
in my server post requests, so I don't think there is any problem with my headers.
Am I doing something wrong? How can I prevent FCM from converting my nested objects?