Push Notifications And Java-Based Servers

Hi,

I’m doing some preliminary research to try to determine the extent to which Corona will work for building apps. I was reading about Push Notifications as they are vital for us going forward and noticed that “a server with PHP installed” was required. A few questions about that: 1. Why is PHP a requirement?

 

  1. Is it possible to get this functional on a Java-based server? Currently a Pro user, considering Enterprise, so that could change my options perhaps?

 

I appreciate any info that I can get on this.

@ericmarston, the server is required by its own nature (as its how it’s designed by Apple):

 

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

 

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9

 

You might find this tutorial helpful:

 

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

 

As far as I understand it, and I could be very wrong but I don’t think PHP is absolutely necessary.  Still you’d need to code in an equivalent language that can receive device token and use it in push request to be sent from the server.

 

Naomi

@ericmarston, the first reply post was all about iOS device.  But now I’m looking into setting up push notification for Android apps, and I came across this thread.  It might be of interest to you.  Take a look at pages 3 and 4:

 

http://forums.coronalabs.com/topic/26257-push-notifications/

 

If you are going to work with Enterprise version, it sounds like you may be able to have great control over its implementation  (coding in Java.)

 

Meanwhile I am in dire need of some guide & tutorial as to how to get push notification working with Android app… For a start, I’m going to look at the sample code that comes bundled with Corona SDK.

 

Naomi

 

Edit:  And… it actually looks like we don’t need server to send push notifications to Google Play apps (except that I’m not sure how I may send a specific notice to a specific device, which is necessary for two-player app, notifying each other when one player completed a game or started a game with the other…)  

 

Anyhow, take a look at CoronaSDK > SampleCode > Notifications > GooglePushNotifications

@Naomi, thanks for the info! Your info pretty much cemented what my own research was turning up. Looks like if we go Enterprise, I can use JAVA APNS http://code.google.com/p/javapns/

 

As for the android stuff, maybe a dev or someone will drop in and shed some light.

@ericmarston, cool.  Glad you worked it out. 

 

About Android version, it actually looks like it works just like iOS version in terms of retrieving device token.  I wasn’t reading the googleRegistrationId variable right the first time around.  It sounded as if the googleRegistrationId is app specific ID, rather than the device specific – but now after the third read, I’ve come to conclude it might just mean the same as iOS’s device token.  So I’m all good.

 

Cheers,

Naomi

You shouldn’t need to use Enterprise to do this (well you will to use javapns).   Lets look at the process:

 

Your app need’s to “register” it’s device toking with some web service (It could be Urban Airship, Corona Cloud, Pushwoosh, or create your own).  That web service remembers the devices that go with your app and use the various key/cert’s for your app.

 

Then once you have a database of device ID’s you can then use whatever means you want to take a message, read a list of devices form the database, open a network socket to Apple’s servers, pass data to them and respond back that the post was successful.

 

Many people have access to PHP and MySQL based servers, so providing a sample in PHP makes sense.  There is no reason you could not do the same thing using C or host side java or jsp to accomplish this.

Rob, 

 

Since this thread has your attention, I have a few questions regarding Android notifications.

 

  1.  Does the Corona client request a registration ID on every start?  According to Google’s GCM docs the registration ID should be stored and only requested if it does not exist.  Also the registration ID might change on the GCM side from time to time.  How does Corona handle this case?

 

  1.  How does one go about un-registering a device from push notifications?

 

Thanks.

 

Nathan.

@ericmarston, the server is required by its own nature (as its how it’s designed by Apple):

 

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

 

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9

 

You might find this tutorial helpful:

 

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

 

As far as I understand it, and I could be very wrong but I don’t think PHP is absolutely necessary.  Still you’d need to code in an equivalent language that can receive device token and use it in push request to be sent from the server.

 

Naomi

@ericmarston, the first reply post was all about iOS device.  But now I’m looking into setting up push notification for Android apps, and I came across this thread.  It might be of interest to you.  Take a look at pages 3 and 4:

 

http://forums.coronalabs.com/topic/26257-push-notifications/

 

If you are going to work with Enterprise version, it sounds like you may be able to have great control over its implementation  (coding in Java.)

 

Meanwhile I am in dire need of some guide & tutorial as to how to get push notification working with Android app… For a start, I’m going to look at the sample code that comes bundled with Corona SDK.

 

Naomi

 

Edit:  And… it actually looks like we don’t need server to send push notifications to Google Play apps (except that I’m not sure how I may send a specific notice to a specific device, which is necessary for two-player app, notifying each other when one player completed a game or started a game with the other…)  

 

Anyhow, take a look at CoronaSDK > SampleCode > Notifications > GooglePushNotifications

@Naomi, thanks for the info! Your info pretty much cemented what my own research was turning up. Looks like if we go Enterprise, I can use JAVA APNS http://code.google.com/p/javapns/

 

As for the android stuff, maybe a dev or someone will drop in and shed some light.

@ericmarston, cool.  Glad you worked it out. 

 

About Android version, it actually looks like it works just like iOS version in terms of retrieving device token.  I wasn’t reading the googleRegistrationId variable right the first time around.  It sounded as if the googleRegistrationId is app specific ID, rather than the device specific – but now after the third read, I’ve come to conclude it might just mean the same as iOS’s device token.  So I’m all good.

 

Cheers,

Naomi

You shouldn’t need to use Enterprise to do this (well you will to use javapns).   Lets look at the process:

 

Your app need’s to “register” it’s device toking with some web service (It could be Urban Airship, Corona Cloud, Pushwoosh, or create your own).  That web service remembers the devices that go with your app and use the various key/cert’s for your app.

 

Then once you have a database of device ID’s you can then use whatever means you want to take a message, read a list of devices form the database, open a network socket to Apple’s servers, pass data to them and respond back that the post was successful.

 

Many people have access to PHP and MySQL based servers, so providing a sample in PHP makes sense.  There is no reason you could not do the same thing using C or host side java or jsp to accomplish this.

Everyone,

To send a push notification, you just need to post a JSON message via HTTP as documented by Google here…

http://developer.android.com/google/gcm/gcm.html#send-msg

You do not have to use PHP.  You can use whatever language/framework that you prefer that is capable of sending a HTTP request to Google’s GCM servers.  For example, check out sample project “Notifications/GooglePushNotifications” that is included with the Corona SDK.  Notice that the sample app pushes a notification to itself by posting a JSON message directly to Google servers via Corona’s “network.request()” API.  In fact, that sample project is very well documented, telling you how to construct the JSON packet and what the various HTTP responses mean.

Also, have a look at the sample project’s “config.lua” file which tells you where to get Google “project number” to get push notifications working.  Google has really made this super easy to set up compared to iOS.

Boark,

Corona does not request for a registration ID from GCM multiple times.  Once a registration ID has been received, Corona caches it and uses that ID from then on.

If you change the project number in your “config.lua” file, then Corona will unregister the last registration ID it has received (if any), and then request a new registration ID with your new project number which will be cached once received.  This happens on app startup.

If you remove the project number from your “config.lua” file, then Corona will unregister the last registration ID it had cached (if any) on app startup and then clear the cached registration ID.

The above is pretty well tested, because we thought these would be common issues during testing/experimenting with Google push notifications.

Regarding Google expiring registration IDs, honestly, it isn’t clear to me how Google handles that.  I would imagine that Google would send an “unregister” intent to the application, which Corona would then automatically clear its cached registration ID, but I see nothing in Google documentation or sample code that allows us to recognize if the unregister notification was triggered by Corona unregistering itself or if it was initiated by Google.  So, Corona will not automatically re-register for a new ID afterwards… but that said, Corona would attempt to re-register on the next app startup since it will recognize that there is no cached registration ID.  Note that an app on Android will effectively restart when you press the Back button and then go back into the app.

Anyways, I hope this helps.

Rob, 

 

Since this thread has your attention, I have a few questions regarding Android notifications.

 

  1.  Does the Corona client request a registration ID on every start?  According to Google’s GCM docs the registration ID should be stored and only requested if it does not exist.  Also the registration ID might change on the GCM side from time to time.  How does Corona handle this case?

 

  1.  How does one go about un-registering a device from push notifications?

 

Thanks.

 

Nathan.

Everyone,

To send a push notification, you just need to post a JSON message via HTTP as documented by Google here…

http://developer.android.com/google/gcm/gcm.html#send-msg

You do not have to use PHP.  You can use whatever language/framework that you prefer that is capable of sending a HTTP request to Google’s GCM servers.  For example, check out sample project “Notifications/GooglePushNotifications” that is included with the Corona SDK.  Notice that the sample app pushes a notification to itself by posting a JSON message directly to Google servers via Corona’s “network.request()” API.  In fact, that sample project is very well documented, telling you how to construct the JSON packet and what the various HTTP responses mean.

Also, have a look at the sample project’s “config.lua” file which tells you where to get Google “project number” to get push notifications working.  Google has really made this super easy to set up compared to iOS.

Boark,

Corona does not request for a registration ID from GCM multiple times.  Once a registration ID has been received, Corona caches it and uses that ID from then on.

If you change the project number in your “config.lua” file, then Corona will unregister the last registration ID it has received (if any), and then request a new registration ID with your new project number which will be cached once received.  This happens on app startup.

If you remove the project number from your “config.lua” file, then Corona will unregister the last registration ID it had cached (if any) on app startup and then clear the cached registration ID.

The above is pretty well tested, because we thought these would be common issues during testing/experimenting with Google push notifications.

Regarding Google expiring registration IDs, honestly, it isn’t clear to me how Google handles that.  I would imagine that Google would send an “unregister” intent to the application, which Corona would then automatically clear its cached registration ID, but I see nothing in Google documentation or sample code that allows us to recognize if the unregister notification was triggered by Corona unregistering itself or if it was initiated by Google.  So, Corona will not automatically re-register for a new ID afterwards… but that said, Corona would attempt to re-register on the next app startup since it will recognize that there is no cached registration ID.  Note that an app on Android will effectively restart when you press the Back button and then go back into the app.

Anyways, I hope this helps.

Im using JavaPNS without the enterprise

Im using JavaPNS without the enterprise

Hi Experts ,

Can you please advice me how the “javapns” api will be invoked the  push notification  when mysql db is changed ( assume new row is added in any table) …  I am not clear how the mysql changes will known to java webservice so that it can invoke the push api … 

Any help will highly appreciated.

Thanks 

Kind Regards

raky