Push Notifications with EasyAPNS

Hi,

Im totally new to push notifications and i’m trying to implement easyapns.

I already downloaded the files, created the mysql tables, and uploaded the php files to the server. Also I already created and downloaded the certificates from apple to my computer but I dont know how to proced now.

Has anyone used Easyapns to send push notifications? 

There seamed to be a tutorial on this here  http://coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/ but it has been removed :S

Please help.

Thanks in advanced

Hi,

Im totally new to push notifications and i’m trying to implement easyapns.

I already downloaded the files, created the mysql tables, and uploaded the php files to the server. Also I already created and downloaded the certificates from apple to my computer but I dont know how to proced now.

Has anyone used Easyapns to send push notifications? 

There seamed to be a tutorial on this here  http://coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/ but it has been removed :S

Please help.

Thanks in advanced

Honestly you’ll be better off using www.pushwoosh.com - its super easy to setup (has free plan) and is cross platform compatible (android/ios/windows)

@contreras2004,

If you opt for PushWoosh, be sure to check out the excellent set of tutorials by two Corona ambassadors at the following link, listed under “3rd-Party”:

http://coronalabs.com/resources/tutorials/communication-and-social-media/

Brent

The blog post that you referenced is pretty old and really didn’t cover easyapns.  It had it’s own PHP implementation that really did nothing more than let you send a single scripted push.  Back in the day when I was messing with it, I got EasyAPNS running and it worked.  What I couldn’t do is get EasyAPNS running from inside of Wordpress.  Unfortunately that project went away so I didn’t spend a lot of time pursuing it.

I have the PHP source from that blog post if you want to get something to just test with.  I in no way can support this… use it at your own experimentation:

\<?php // Put your device token here (without spaces): // this is the token you get with the remote registration event in Corona SDK $deviceToken = '7f3cfeb48a2a708f875252625fa84c51eb2d4d38ae1b448b04a8e1b12dc984ae'; // Put your private key's passphrase here: $passphrase = 'yourkeypassword'; // Put your alert message here: $message = 'My Corona SDK push notification!'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream\_context\_create(); stream\_context\_set\_option($ctx, 'ssl', 'local\_cert', 'ck\_prod.pem'); stream\_context\_set\_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream\_socket\_client( 'ssl://gateway.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, 'badge' =\> 1, 'sound' =\> 'default' ); // 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; echo strlen($msg); // 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); ?\>

ck_prod.pem is the PEM version of your key.  The passphrase is the password for that key.  This is set for a production server, not the development server.  If you want the development server, change ck_prod.pem to ck_dev.pem (and of course upload the right key to go with it).  Then the URL is something like: ssl://gateway.sandbox.push.apple.com:2195

Hi,

Im totally new to push notifications and i’m trying to implement easyapns.

I already downloaded the files, created the mysql tables, and uploaded the php files to the server. Also I already created and downloaded the certificates from apple to my computer but I dont know how to proced now.

Has anyone used Easyapns to send push notifications? 

There seamed to be a tutorial on this here  http://coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/ but it has been removed :S

Please help.

Thanks in advanced

Honestly you’ll be better off using www.pushwoosh.com - its super easy to setup (has free plan) and is cross platform compatible (android/ios/windows)

@contreras2004,

If you opt for PushWoosh, be sure to check out the excellent set of tutorials by two Corona ambassadors at the following link, listed under “3rd-Party”:

http://coronalabs.com/resources/tutorials/communication-and-social-media/

Brent

The blog post that you referenced is pretty old and really didn’t cover easyapns.  It had it’s own PHP implementation that really did nothing more than let you send a single scripted push.  Back in the day when I was messing with it, I got EasyAPNS running and it worked.  What I couldn’t do is get EasyAPNS running from inside of Wordpress.  Unfortunately that project went away so I didn’t spend a lot of time pursuing it.

I have the PHP source from that blog post if you want to get something to just test with.  I in no way can support this… use it at your own experimentation:

\<?php // Put your device token here (without spaces): // this is the token you get with the remote registration event in Corona SDK $deviceToken = '7f3cfeb48a2a708f875252625fa84c51eb2d4d38ae1b448b04a8e1b12dc984ae'; // Put your private key's passphrase here: $passphrase = 'yourkeypassword'; // Put your alert message here: $message = 'My Corona SDK push notification!'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream\_context\_create(); stream\_context\_set\_option($ctx, 'ssl', 'local\_cert', 'ck\_prod.pem'); stream\_context\_set\_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream\_socket\_client( 'ssl://gateway.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, 'badge' =\> 1, 'sound' =\> 'default' ); // 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; echo strlen($msg); // 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); ?\>

ck_prod.pem is the PEM version of your key.  The passphrase is the password for that key.  This is set for a production server, not the development server.  If you want the development server, change ck_prod.pem to ck_dev.pem (and of course upload the right key to go with it).  Then the URL is something like: ssl://gateway.sandbox.push.apple.com:2195