Custom Push Data

Having looked here:

http://www.coronalabs.com/blog/2012/12/25/corona-holiday-gifts-android-push-and-more/
http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk

I am still failing to send and receive custom push notification data on iOS. Does anyone have an example piece of code which does this?

The tutorials I’ve seen simply state that custom data can be attached to the message and retrieved from the notification table, but they don’t actually show this happening. Even the Parse.com tutorial says it’s possible then neatly skips over it.

https://www.parse.com/docs/push_guide#options-data/REST

Unless I am doing it correctly (I’ve tried many combinations) and the current daily build is broken? - 1027 [import]uid: 8271 topic_id: 35869 reply_id: 335869[/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]

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]

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]

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]