Receiving push notifications from parse.com

Hi guys, I’m after some help here - could anyone tell me if it is possible to receive push notifications from parse .com and if so how do you set it up in Corona?  I played with the code off their site and I can read/write to their cloud database but there are no devices registered to send notifications to!  Any help much appreciated.

For iOS you have to setup Corona to use push notifications from Apple. You can see how to set that up here:

http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/

Once you have that, you will get a device token when the app runs. Register the device token with Parse by posting the token to “Installations” using the REST API.

If you want to push to Android, then it becomes costly and a hassle. You need the Parse SDK which in turn requires Enterprise. I have made a native Android app to get the device ID which Parse needs for Android push and set it up to receive. It was literally 4 lines of code. The small app works fine on my Android devices.

Unless Corona allows us to use plugins from our local computers with Pro, I don’t think I will take the dive. Paying $1000 yearly and losing the ease of Pro, just to continue using a small chunk of code and 1 SDK, isn’t realistic. I have already confirmed with Parse they have no interest in making a plugin for Corona.

You might want to check our our new Push/Local notification guide:

http://docs.coronalabs.com/guide/events/appNotification/index.html

It shows how to register with PushWoosh, but registering with Parse shouldn’t be too terribly different.

Fantastic, thanks guys.  I hadn’t seen the installation part, just working on it now.

Hmm it’s registered fine but the push notifications just aren’t coming back?

Hmm it’s registered fine but the push notifications just aren’t coming back?

“Coming back” as in you are sending from device? If you are using Pushwoosh you can’t use the remote API without paying.

OK so it was a problem with the certificates, re-did those and it sprung into life!  Thanks for the pointers once again guys.

For anyone reading this I will drop the code here so you can see how it worked in it’s simplest stripped back form because it may save you a lot of searching the net and parse help pages:

All we wanted to do was receive push notifications sent from Parse.com and nothing else so we essentially used this code: 

local launchArgs = ... local json = require "json" local baseUrl = "https://api.parse.com/1/installations/" local headers = {} headers["Content-Type"] = "application/json" headers["X-Parse-Application-Id"] = "bGwKA4hQqWRs8AO52f1jwdykrYbUJ572zEgJMTvu" headers["X-Parse-REST-API-Key"] = "VSsLq6lVS880qSGIVkA2Kk2IKcb81qjv51Q4x4yM" local params = {} params.headers = headers local function networkListener( event ) if ( event.isError ) then print( "Network error!") else print("RESPONSE: " .. event.response) end end --Send the message over with the new token local function post ( message ) params.body = json.encode ( message ) network.request( baseUrl, "POST", networkListener, params) end -- notification listener local function onNotification( event ) if event.type == "remoteRegistration" then message = {deviceType = "ios", deviceToken = event.token, channels = {""}} post(message) elseif event.type == "remote" then end end Runtime:addEventListener( "notification", onNotification )

If it is successful you get a print statement saying something like created and the date and an object ID.  If you log into your dashboard on parse then you will be able to send push notifications from there and also see how many installed devices you have etc.

There are bits and bobs taken from here:

http://developer.coronalabs.com/forum/2011/09/27/parse-backend

and here:

http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/

and there is an overview of how to send messages here:

https://parse.com/docs/rest

For iOS you have to setup Corona to use push notifications from Apple. You can see how to set that up here:

http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/

Once you have that, you will get a device token when the app runs. Register the device token with Parse by posting the token to “Installations” using the REST API.

If you want to push to Android, then it becomes costly and a hassle. You need the Parse SDK which in turn requires Enterprise. I have made a native Android app to get the device ID which Parse needs for Android push and set it up to receive. It was literally 4 lines of code. The small app works fine on my Android devices.

Unless Corona allows us to use plugins from our local computers with Pro, I don’t think I will take the dive. Paying $1000 yearly and losing the ease of Pro, just to continue using a small chunk of code and 1 SDK, isn’t realistic. I have already confirmed with Parse they have no interest in making a plugin for Corona.

You might want to check our our new Push/Local notification guide:

http://docs.coronalabs.com/guide/events/appNotification/index.html

It shows how to register with PushWoosh, but registering with Parse shouldn’t be too terribly different.

Fantastic, thanks guys.  I hadn’t seen the installation part, just working on it now.

Hmm it’s registered fine but the push notifications just aren’t coming back?

Hmm it’s registered fine but the push notifications just aren’t coming back?

“Coming back” as in you are sending from device? If you are using Pushwoosh you can’t use the remote API without paying.

OK so it was a problem with the certificates, re-did those and it sprung into life!  Thanks for the pointers once again guys.

For anyone reading this I will drop the code here so you can see how it worked in it’s simplest stripped back form because it may save you a lot of searching the net and parse help pages:

All we wanted to do was receive push notifications sent from Parse.com and nothing else so we essentially used this code: 

local launchArgs = ... local json = require "json" local baseUrl = "https://api.parse.com/1/installations/" local headers = {} headers["Content-Type"] = "application/json" headers["X-Parse-Application-Id"] = "bGwKA4hQqWRs8AO52f1jwdykrYbUJ572zEgJMTvu" headers["X-Parse-REST-API-Key"] = "VSsLq6lVS880qSGIVkA2Kk2IKcb81qjv51Q4x4yM" local params = {} params.headers = headers local function networkListener( event ) if ( event.isError ) then print( "Network error!") else print("RESPONSE: " .. event.response) end end --Send the message over with the new token local function post ( message ) params.body = json.encode ( message ) network.request( baseUrl, "POST", networkListener, params) end -- notification listener local function onNotification( event ) if event.type == "remoteRegistration" then message = {deviceType = "ios", deviceToken = event.token, channels = {""}} post(message) elseif event.type == "remote" then end end Runtime:addEventListener( "notification", onNotification )

If it is successful you get a print statement saying something like created and the date and an object ID.  If you log into your dashboard on parse then you will be able to send push notifications from there and also see how many installed devices you have etc.

There are bits and bobs taken from here:

http://developer.coronalabs.com/forum/2011/09/27/parse-backend

and here:

http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/

and there is an overview of how to send messages here:

https://parse.com/docs/rest