Push notification Titanium shows whole payload instead of the actual message

367 views Asked by At

I'm using cURL to send push notifications to appcelerator, been using this for a while without problems.

Suddenly appcelerator can't handle the JSON payload and shows the whole JSON string as an message on the actual device. This is what our curl post data looks like:

channel=dev&payload={"alert":"The Message","title":"Title","vibrate":true, content-available:1, "badge":"+1", "sound":"default", "id":617, "icon":"appicon"}&to_ids=everyone

And this is what my device shows as push notification:

"{
   "alert":"The Message",
   "title":"Title",
   "vibrate":true, 
    content-available:1, 
   "badge":"+1", 
   "sound":"default", 
   "id":617, 
   "icon":"appicon"
 }"

instead of: "The Message"

2

There are 2 answers

2
Jeroen On BEST ANSWER

Turns out there was a \n in the JSON that broke the JSON string. building a Array first then using json_encode() in PHP fixed the issue

2
Rene Pot On

You will need to parse the JSON that comes in your app. The payload is JSON.

So, assuming the payload comes in with the variable data, you need to do this:

alert(JSON.parse(data).alert);

This will display the alert property of the payload.