Custom Push Data

It’s basically the same as the PHP code in the push notifications blog post.

[code]

<?php
// Put your device token here (without spaces): $deviceToken = '61970bfb630b0ad43b54ccd006e110d6834604b2b03df70146f03ea48fe3ac24'; // Put your private key's passphrase here: $passphrase = 'XXXXXXX'; // Put your alert message here: $message = 'An OSM Corona SDK push notification from '; $message .= php\_uname('n'); echo "message: $message\n"; //////////////////////////////////////////////////////////////////////////////// $ctx = stream\_context\_create(); stream\_context\_set\_option($ctx, 'ssl', 'local\_cert', 'ck.pem'); stream\_context\_set\_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream\_socket\_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM\_CLIENT\_CONNECT|STREAM\_CLIENT\_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP\_EOL); echo 'Connected to APNS' . PHP\_EOL; // Create the payload body $body['aps'] = array( 'alert' =\> $message, 'sound' =\> 'default', 'badge' =\> 4, 'custom' =\> array('anumber' =\> 1, 'aboolean' =\> true, 'astring' =\> 'stringvalue', 'afloat' =\> 3.1415), 'random' =\> 'RaNdOm', ); // Encode the payload as JSON $payload = json\_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H\*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP\_EOL; else echo 'Message successfully delivered' . PHP\_EOL; // Close the connection to the server fclose($fp); ?\> [/code] [import]uid: 199237 topic\_id: 35869 reply\_id: 142940[/import]

The URL I call is: https://api.parse.com/1/push/
The body of the request is:

{“data”:{“badge”:“Increment”,“custom”:{“entry”:“erk!”,“arg”:“Garble!”},“alert”:“This is a test message from tester1@mailinator.com”,“title”:"This is a test message from "},“channels”:[“Atester2_mailinator_com”]}

In my test app I dump the raw message received and it always contains an empty custom element:

{“badge”:5,“type”:“remote”,“name”:“notification”,“custom”:[],“alert”:“This is a test message from tester1@mailinator.com”,“applicationState”:“active”}

I just can’t figure out why the custom element is empty. [import]uid: 8271 topic_id: 35869 reply_id: 144670[/import]

Has anyone been able to integrate parse.com for push with Android? I have it working well for iOs but Android…what a pain. :frowning: [import]uid: 81642 topic_id: 35869 reply_id: 144727[/import]

I’ve recently added the “custom” value to my config.lua, but this did not help.

I see you’ve tried sending the push with custom data from the sendpush.php but receiving it with my Corona code, yes?

Have you tried sending the push with custom data from corona code via the Parse API - which is where I’m getting stuck? [import]uid: 8271 topic_id: 35869 reply_id: 143080[/import]

I just retested with build 1027 and all seems well. On my iPhone I get the following data in the notification:
[blockcode]
Feb 14 11:29:00 Perrys-iPhone NotificationsTester[12856] Warning: remote: event: {“badge”:4,“type”:“remote”,“name”:“notification”,“custom”:{“aboolean”:true,“afloat”:3.1415,“astring”:“stringvalue”,“anumber”:1},“sound”:“default”,“alert”:“An OSM Corona SDK push notification from Perrys-MacBook.local”,“applicationState”:“active”}
[/blockcode]
Reformating the JSON for readability yields:
[blockcode]
{
“badge” : 4,
“type” : “remote”,
“name” : “notification”,
“custom” : {
“aboolean” : true,
“afloat” : 3.1415,
“astring” : “stringvalue”,
“anumber” : 1
},
“sound” : “default”,
“alert” : “An OSM Corona SDK push notification from Perrys-MacBook.local”,
“applicationState” : “active”
}
[/blockcode]
This is what I sent to the notification system with the addition of type, name and applicationState which it provided. [import]uid: 199237 topic_id: 35869 reply_id: 142790[/import]

Would you be able to post the line of code you used to provide the custom data, please? [import]uid: 8271 topic_id: 35869 reply_id: 142831[/import]

Also, have you seen this post?

https://developer.coronalabs.com/forum/2013/02/14/sending-push-custom-data [import]uid: 8271 topic_id: 35869 reply_id: 142832[/import]

It’s basically the same as the PHP code in the push notifications blog post.

[code]

<?php
// Put your device token here (without spaces): $deviceToken = '61970bfb630b0ad43b54ccd006e110d6834604b2b03df70146f03ea48fe3ac24'; // Put your private key's passphrase here: $passphrase = 'XXXXXXX'; // Put your alert message here: $message = 'An OSM Corona SDK push notification from '; $message .= php\_uname('n'); echo "message: $message\n"; //////////////////////////////////////////////////////////////////////////////// $ctx = stream\_context\_create(); stream\_context\_set\_option($ctx, 'ssl', 'local\_cert', 'ck.pem'); stream\_context\_set\_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream\_socket\_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM\_CLIENT\_CONNECT|STREAM\_CLIENT\_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP\_EOL); echo 'Connected to APNS' . PHP\_EOL; // Create the payload body $body['aps'] = array( 'alert' =\> $message, 'sound' =\> 'default', 'badge' =\> 4, 'custom' =\> array('anumber' =\> 1, 'aboolean' =\> true, 'astring' =\> 'stringvalue', 'afloat' =\> 3.1415), 'random' =\> 'RaNdOm', ); // Encode the payload as JSON $payload = json\_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H\*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP\_EOL; else echo 'Message successfully delivered' . PHP\_EOL; // Close the connection to the server fclose($fp); ?\> [/code] [import]uid: 199237 topic\_id: 35869 reply\_id: 142940[/import]

I’ve recently added the “custom” value to my config.lua, but this did not help.

I see you’ve tried sending the push with custom data from the sendpush.php but receiving it with my Corona code, yes?

Have you tried sending the push with custom data from corona code via the Parse API - which is where I’m getting stuck? [import]uid: 8271 topic_id: 35869 reply_id: 143080[/import]

This is what I have in my config.lua (“custom” doesn’t need to be mentioned).

 notification =  
 {  
 iphone =  
 {  
 types =  
 {  
 "badge", "sound", "alert"  
 }  
 }  
 }  

I haven’t tried Parse. Have you asked their support whether it’s expected to work (you mentioned above that their sample code glosses over the case)? [import]uid: 199237 topic_id: 35869 reply_id: 144453[/import]

One more thing, can you post the JSON you’re sending and the JSON you receive in your app? From your description I assume they’re the same with the exception of the custom field but maybe something will leap out. [import]uid: 199237 topic_id: 35869 reply_id: 144454[/import]

The URL I call is: https://api.parse.com/1/push/
The body of the request is:

{“data”:{“badge”:“Increment”,“custom”:{“entry”:“erk!”,“arg”:“Garble!”},“alert”:“This is a test message from tester1@mailinator.com”,“title”:"This is a test message from "},“channels”:[“Atester2_mailinator_com”]}

In my test app I dump the raw message received and it always contains an empty custom element:

{“badge”:5,“type”:“remote”,“name”:“notification”,“custom”:[],“alert”:“This is a test message from tester1@mailinator.com”,“applicationState”:“active”}

I just can’t figure out why the custom element is empty. [import]uid: 8271 topic_id: 35869 reply_id: 144670[/import]

Has anyone been able to integrate parse.com for push with Android? I have it working well for iOs but Android…what a pain. :frowning: [import]uid: 81642 topic_id: 35869 reply_id: 144727[/import]

It’s curious that the “custom” element gets changed from an object (defined with {} in JSON) to a list (defined with []).

Before:{ "data" : { "badge" : "Increment", "custom" : { "entry" : "erk!", "arg" : "Garble!" }, "alert" : "This?is a test message from tester1@mailinator.com", "title" : "This is a test?message from " }, "channels" : [ "Atester2\_mailinator\_com" ] }

After:[code]{
“badge” : 5,
“type” : “remote”,
“name” : “notification”,
“custom” : [

],
“alert” : “This is a test message from tester1@mailinator.com”,
“applicationState” : “active”
}[/code]

We’re just forwarding the JSON that we receive without interpreting it so I have to assume that something or someone upstream is causing this.

You could try seeing if specifying “custom” as a list of items works any better in your environment:{ "data" : { "badge" : "Increment", "title" : "This is a test message from ", "custom" : [ "erk!", "Garble!" ], "alert" : "This is a test message from tester1@mailinator.com" }, "channels" : [ "Atester2\_mailinator\_com" ] }

I’m pretty sure that the change to “custom” isn’t caused by anything we’re doing.
[import]uid: 199237 topic_id: 35869 reply_id: 145469[/import]

This is what I have in my config.lua (“custom” doesn’t need to be mentioned).

 notification =  
 {  
 iphone =  
 {  
 types =  
 {  
 "badge", "sound", "alert"  
 }  
 }  
 }  

I haven’t tried Parse. Have you asked their support whether it’s expected to work (you mentioned above that their sample code glosses over the case)? [import]uid: 199237 topic_id: 35869 reply_id: 144453[/import]

One more thing, can you post the JSON you’re sending and the JSON you receive in your app? From your description I assume they’re the same with the exception of the custom field but maybe something will leap out. [import]uid: 199237 topic_id: 35869 reply_id: 144454[/import]

The URL I call is: https://api.parse.com/1/push/
The body of the request is:

{“data”:{“badge”:“Increment”,“custom”:{“entry”:“erk!”,“arg”:“Garble!”},“alert”:“This is a test message from tester1@mailinator.com”,“title”:"This is a test message from "},“channels”:[“Atester2_mailinator_com”]}

In my test app I dump the raw message received and it always contains an empty custom element:

{“badge”:5,“type”:“remote”,“name”:“notification”,“custom”:[],“alert”:“This is a test message from tester1@mailinator.com”,“applicationState”:“active”}

I just can’t figure out why the custom element is empty. [import]uid: 8271 topic_id: 35869 reply_id: 144670[/import]

Has anyone been able to integrate parse.com for push with Android? I have it working well for iOs but Android…what a pain. :frowning: [import]uid: 81642 topic_id: 35869 reply_id: 144727[/import]

It’s curious that the “custom” element gets changed from an object (defined with {} in JSON) to a list (defined with []).

Before:{ "data" : { "badge" : "Increment", "custom" : { "entry" : "erk!", "arg" : "Garble!" }, "alert" : "This?is a test message from tester1@mailinator.com", "title" : "This is a test?message from " }, "channels" : [ "Atester2\_mailinator\_com" ] }

After:[code]{
“badge” : 5,
“type” : “remote”,
“name” : “notification”,
“custom” : [

],
“alert” : “This is a test message from tester1@mailinator.com”,
“applicationState” : “active”
}[/code]

We’re just forwarding the JSON that we receive without interpreting it so I have to assume that something or someone upstream is causing this.

You could try seeing if specifying “custom” as a list of items works any better in your environment:{ "data" : { "badge" : "Increment", "title" : "This is a test message from ", "custom" : [ "erk!", "Garble!" ], "alert" : "This is a test message from tester1@mailinator.com" }, "channels" : [ "Atester2\_mailinator\_com" ] }

I’m pretty sure that the change to “custom” isn’t caused by anything we’re doing.
[import]uid: 199237 topic_id: 35869 reply_id: 145469[/import]

Although an old thread, it might still be relevant.

Did you try to put the data in as follows:

&nbsp; &nbsp; &nbsp; &nbsp; commands\_json = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ["data"] =&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;["alert"] = "test", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["sound"] = "", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["custom"] = { a = "b" }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;

postData = json.encode(commands\_json) &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local params = {} &nbsp; &nbsp; &nbsp; &nbsp; params.headers = headers &nbsp; &nbsp; &nbsp; &nbsp; params.body = postData &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("params are "..tostring(params)) &nbsp; &nbsp; &nbsp; &nbsp; network.request( "https://api.parse.com/1/push","POST",sendPushListener,params) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

This works for me (finally :).

I could then easily retrieve the table on the receiving end (notificationlistener) in corona like this:

&nbsp; &nbsp; &nbsp; &nbsp; for k,v in pairs(event.custom) do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;print("k = "..k.." and v = "..v) &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp;

k would be the key (a) and v returns value “b”

I did put the custom field in the config.lua btw