Parse Push Notifications working with Corona SDK

So I finally got Push Notifications to work between Parse.com Cloud Service and Corona SDK. I have been struggling for days with matter so I thought I would share the code and steps I used to make it work. I did share it when I made it work with Urban Airship in 2011 and then it was very appreciated.

So, here we go…

  1. Sign up with Parse.com

  2. Create a new APP

  3. Note down the APP ID key and the RESTFUL API key

  4. Make sure you have the correct Mobile Provisioning files from Apple and that they support Push Notifications both development and production. Download them and export them to p12-files without passwords and upload them to the parse server under PUSH.

  5. Make sure you have signed up with Google and enable the messaging service there to and note down the keys and especially the Projectnumber needed later. Enter all this information in the Parse config panel as well under PUSH, just like you did in step 4.

  6. Make the below code insert in config.lua and make sure that you enter the correct number from the project noted from Google API. Make sure projectNumber is with capital N, spent a whole day with this :frowning:

    notification = { iphone = { types = { “badge”, “sound”, “alert” } }, google = { projectNumber = “000” }, },

  7. If you want to support notifications when app is not alive you must also support launchargs so make sure you don’t forget to add that in the code as you can see below.

    local function notificationListener(e) if e.type == ‘local’ then local data = e.custom or _G.emptyTable showAlert(data.title, data.message, {getText(‘option_ok’)}) end if (e.type == “remoteRegistration”) then local jsonEncode = require(‘json’).encode local platform = “ios” if e.token ~= nil then --save the deviceToken as a global so we can grab it later _G.deviceToken = e.token else print(“no token returned, too bad, check certificates”) end local myRegistrationId = e.token if (system.getInfo(“platformName”) == “Android”) then platform = “android” end local function networkListener(event) if (event.isError) then print(" ===>>> PARSE LISTENER ERROR RESPONSE : “, event.response) else print(” ===>>> PARSE LISTENER RESPONSE: “, event.response) end end local headers = { [“X-Parse-Application-Id”] = “your app id key here”, [“X-Parse-REST-API-Key”] = “your restful api key here”, [“Content-Type”] = “application/json” } local bodyData = { – These two fields must be added at parse.com first. [“deviceName”] = tostring( system.getInfo(“name”) ), [“deviceModel”] = tostring( system.getInfo(“architectureInfo”) ), [“deviceType”] = platform, [“deviceToken”] = _G.deviceToken, [“badge”] = native.getProperty(“applicationIconBadgeNumber”), [“timeZone”] = print(os.date(”%Z")), [“channels”] = {“your channels here”, “or more channels here”}, [“appName”] = “special app name used to filter push”, } local bodyMessage = jsonEncode(bodyData) local params = { headers = headers, body = bodyMessage } network.request( “https://api.parse.com/1/installations” ,“POST”, networkListener, params) elseif e.type == “remote” then native.showAlert( “Andreas Kviby”, e.alert , { “OK” } ) end end – Add event listener here Runtime:addEventListener(‘notification’, notificationListener) local launchArgs = … if ( launchArgs and launchArgs.notification ) then print( “event via launchArgs” ) notificationListener( launchArgs.notification ) end

You add the code above in your main.lua file and then make sure you build your app with the correct mobile provision certificate and try it? Deploy to device (NOT POSSIBLE TO TEST IN SIMULATOR!) and start the device and if everything goes well you can launch parse.com and send your first push in minutes!

So great to finally have everything working at last!

There is one thing not working in this code… The Push get sent empty to all Android devices :frowning: Working on it.

I have the same problem on android devices. Is it the problem of parse.com?

yes, it seem that it has to do with parse. Game thrive worked asap.

Maybe so.

Even if it’s true, the name of parse.com is contained in the document of ‘push notification’, isn’t it?

I hope Corona staff can do something to help us out :wink:

Thanks.

Hi @nappa,

We provide a very basic example for PushWoosh (recently tested) in our guide. However, we can not provide an example for every 3rd-party push notification service, so you’ll need to contact them or seek out if they’ve provided any documentation on their side for using their service with Corona.

Thanks,

Brent

Brent,

That makes sence. I’m going to ask parse.com about it.

Thanks.

This problem were easily resolved using gamethrive.com. I give parse.com up as a bad job.

Im not sure because I haven’t tried it out on android my self yet. But don’t you need “google cloud messages” tag in your installation for android devices so that pushes can work like supposed to? that is in conjunction with the project number from google?

  • pushType : This field is reserved for directing Parse to the push delivery network to be used. If the device is registered to receive pushes via GCM, this field will be marked “gcm”. If this device is not using GCM, and is using Parse’s push notification service, it will be blank (readonly).

Hi sam.bavi,

When using parse.com, If you do not set “gcm” to ‘pushType’ field, a notification does not reach android devices.

And even if you set “gcm”, ‘alert’ and ‘custom’ fields in a notification is empty.

BTW, if you do not set ‘undefined’(not blank string) to ‘pushType’ field, a notification does not reach iphone.

Thank you.

Hi nappa, dont understand that last part, i just checked my tables at parse and ‘pushType’ is automatically set to ‘undefined’ when not set and its working on iOS 8. Or what that what you meant?

sam.bavi,

Never mind. When registering devices using REST API, and I set a blank string(not ‘undefined’) to ‘pushType’, a notification can’t reach devices. 

Thanks.

Hi nappa, were you able to successfully register the android device on parse? At the moment I’m getting an error that installationId is missing, but Im not sure were to get the installationId from. Did you use device id?  

sam.bavi,

>were you able to successfully register the android device on parse? 
>Did you use device id?
yes. you can register a device to parse.com with a registration id that was retrieved by “remoteRegistration” event on android device.

There is one thing not working in this code… The Push get sent empty to all Android devices :frowning: Working on it.

So on a Non-Google Android phone, is that possible to push notification using Parse like you? 

There is no Google Service on that phone and I don’t have a Google  projectNumber.

Hi hexor, I don’t know, haven’t used parse sense after that my self. Moved on to gamethrive plugin. If you by non google you mean amazon then I can highly recommend gamethrive for this. I have my self used gamethrive for amazon and its really easy to setup after you register your app in their developer portal. You need to register the app in google play to get an Google  projectNumber,  I don’t know if you need google services to use push? But for developer purposes I usually install gapps (google services) on my android emulator builds manually.

I have the same problem on android devices. Is it the problem of parse.com?

yes, it seem that it has to do with parse. Game thrive worked asap.

Maybe so.

Even if it’s true, the name of parse.com is contained in the document of ‘push notification’, isn’t it?

I hope Corona staff can do something to help us out :wink:

Thanks.