Open maximilianloy opened 7 years ago
@maximilianloy can you give me the full push payload? Also, how do you send the push info as I can't reproduce?
@macdonst I updated the issue. Thank you for your help!
If an additional property is not a js primitive, it should not be stringified, basically.
@maximilianloy ah, you are using GCM on iOS then? My test was with APNS on iOS.
Related to #1710?
@fredgalvao sorry, but I do not understand. Is there any other way to send nested objects?
@maximilianloy I was just making a note, because that other issue (#1710) is most probably the same root issue as this one: unproper parsing/stringifying of a nested object from the payload. If one is fixed, the other will probably be fixed by consequence.
This is my current workaround, (recursively) iterating through the data and checking if it needs to be parsed:
function parseIfJson(str) {
try {
return JSON.parse(str);
} catch (e) {
return str;
}
}
function iterateParse(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
obj[property] = parseIfJson(obj[property]);
if (typeof obj[property] == 'object') {
iterate(obj[property]);
}
}
}
return obj;
}
var push = PushNotification.init({...});
push.on('notification', function(data) {
var reparsedJson = iterateParse(data);
console.log('Push data', reparsedJson.additionalData);
push.finish();
});
@maximilianloy yeah, this seems to be a bug with the way GCM on iOS delivers the info to the plugin. When I send via APNS on iOS with a payload of:
{"aps":{"alert":"Testing.. (2)","badge":1,"sound":"default", "data": {
"attr_1": 1,
"attr_2": "value_2",
"more": {
"nested_attr_a": 3,
"nested_attr_b": "value_b"
}
}
}}
then the additionalData
object is correctly setup.
Could that be the root cause for this issue https://github.com/phonegap/phonegap-plugin-push/issues/1577#issuecomment-300920397 as well?
@bardu Considering the following payload json as the one the OP reports there, I'd say it could indeed:
{
"data": {
"title": "",
"message": "",
"image": "",
"extra": {//nestedObject
"url": ""
}
},
"to": "device-id",
"notification": {
"title": "",
"body": ""
}
};
@fredgalvao That's what I'm thinking too!
This is still the case using FCM and version 2.0.0
Expected Behaviour
additionalData is:
Actual Behaviour
additionalData is:
Reproduce Scenario (including but not limited to)
POST push message to GCM (https://gcm-http.googleapis.com/gcm/send)
POST payload:
Steps to Reproduce
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
iOS 10.3.1 iPhone 5s + 6
(Android) What device vendor (e.g. Samsung, HTC, Sony...)
Nexus 5
Cordova CLI version and cordova platform version
Plugin version
Sample Push Data Payload
Sample Code that illustrates the problem
Logs taken while reproducing problem