I am sending push notifications via a PHP script to connect to APNS server. Everything is working fine when I use the below payload structure.
$body['aps'] = array(
'alert' => $message,
'badge' => $badge,
'sound' => 'default'
);
$payload = json_encode($body);
However, I need to add more parameters to the 'alert' element as well as want to add some more custom parameters. The way I do is is as follows, but APNS is not accepting the JSON. Is it a problem with my JSON creation method in PHP?
$payload='{
"aps": {
"alert":{
"title": "'.$message.'",
"body":"'.$notif_desc.'"
},
"badge":"'.$badge.'",
"sound": "default"
},
"type": "notification",
"id":"'.$lastid.'",
"date:"'.$date1.'"
}';
So basically, I have two queries. IS the second method wrong? If so, please show me a valid method to create nested JSON Payload for APNS server. Second question, I need to add custom PHP variables to the Payload, I want to know whether the way I have added it in the second method is right or wrong.
basically, I need to create a JSON object as below in PHP
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}