Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APNS JSON PAYLOAD - more arguments

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?

like image 498
sebastian Avatar asked May 10 '11 18:05

sebastian


People also ask

What is the payload size of APNs?

Apple Push Notification service (APNs) refuses a notification if the total size of its payload exceeds the following limits: For Voice over Internet Protocol (VoIP) notifications, the maximum payload size is 5 KB (5120 bytes). For all other remote notifications, the maximum payload size is 4 KB (4096 bytes).

What is the size of payload in regular remote push notification?

Notification messages can contain an optional data payload. Maximum payload for both message types is 4000 bytes, except when sending messages from the Firebase console, which enforces a 1024 character limit.

What is push notification payload?

Push payloads are sent with encrypted content when the mobile app supplies an RSA public encryption key upon push registration with the Salesforce push notification service. When a payload is sent from a customer org to a user's device, the mobile app processes and decrypts the payload.

What is rich push notification in IOS?

Rich push notifications are short pop-up messages sent to a user's device with a rich media attachment such as an animated GIF, video, or audio. They allow you to communicate with your customers in an inviting way even when they're not actively using your app or visiting your website.


2 Answers

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.

like image 92
lostInTransit Avatar answered Oct 07 '22 17:10

lostInTransit


In case someone is still wondering :

$body = (array('aps' => array('alert' => $message,'sound' => $sound_file_wav),   "some_key" => "custom_id"));
$payload = json_encode($body);
like image 40
amol-c Avatar answered Oct 07 '22 15:10

amol-c