9

I need to add some arguments to a json payload for APNS service. How can i do this? this is the documentation of apple: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

When i try to send a message with close and view buttons, i need to add two more arguments that my mobile application needs. Any idea?

Kara
  • 6,115
  • 16
  • 50
  • 57
sebastian
  • 93
  • 1
  • 1
  • 3

3 Answers3

25

Not sure if you got the answer yet. But this is what the documentation mentions

Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean.

So in order to add custom values to your payload, just add them as key-value pairs in your payload. Something like this

{
    "aps":{
        "alert":"Your Message",
        "sound":"push1.wav"
     },
     "custom_key1":"value1",
     "custom_key2":"value2"
}

Here custom_key1 and custom_key2 are your custom keys and value1 and value2 are their values.

Wilt
  • 41,477
  • 12
  • 152
  • 203
lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • Im still having the same problem with APNS. When i receive the notification, im only have a "close" button, but i need the "close" and "view" button. When i send this Payload: { "aps":{"alert":"test Message"}, "acme2" : ["bang","whiz"] } i have the buttons that i need, but, how can i put two more arguments like: "argument1":"value1","argument2":"value2" ?. – sebastian May 13 '11 at 19:54
  • the example I have above uses 2 arguments (custom key1 and key2). To get the keys you have to handle the app delegate method. – lostInTransit May 14 '11 at 09:01
1

In case someone is still wondering :

$body = (array('aps' => array('alert' => $message,'sound' => $sound_file_wav),   "some_key" => "custom_id"));
$payload = json_encode($body);
amol-c
  • 435
  • 4
  • 10
0

I use the following in PHP

$title = 'My Test Message';
$sound = 'doorbell.caf';
$msgpayload=json_encode(array('aps' => array('alert' => $title,'sound' => $sound,)));


$response = $sns->publish(array(
    'TopicArn' => $TopicArn,
    'MessageStructure' => 'json',
    'Message' => json_encode(array(
        'default' => $title,
        'APNS_SANDBOX' => $msgpayload
    ))
));
raju_kr
  • 143
  • 2
  • 11