Using Push Notifications with your OWN server (how to register)

Hello,

We are working on an app that requires to get push notifications

I couldn’t get PushWoosh to work (device logged succesful, but there were no subscribers)

so the people I’m working with followed some instructions on how to configure their own server to send notifications to GCM. However, the instructions included information on how to register the device using native language on eclipse (which I’m not familiar with) and since the rest of the app is being developed with Corona SDK I need to get the registration to work from Corona as well.

I looked for a way to do this but so far I’ve only found the sample for registering with PushWoosh, I don’t know what information is required when you are using your own server, or how to send it from Corona.

Register code:

\<?php require\_once('loader.php'); // return json response $json = array(); $nameUser = $\_POST["name"]; $nameEmail = $\_POST["email"]; // GCM Registration ID got from device $gcmRegID = $\_POST["regId"]; /\*\* \* Registering a user device in database \* Store reg id in users table \*/ if (isset($nameUser) && isset($nameEmail) && isset($gcmRegID)) { // Store user details in db $res = storeUser($nameUser, $nameEmail, $gcmRegID); $registatoin\_ids = array($gcmRegID); $message = array("product" =\> "shirt"); $result = send\_push\_notification($registatoin\_ids, $message); echo $result; } else { // user details not found } ?\>

What instructions an information do I need to send from Corona in rder to register with the server?

Thank you.

Edit:

According to the example, if I was writing in native code, I would need to do this:

 void register(final Context context, String name, String email, final String regId) { Log.i(Config.TAG, "registering device (regId = " + regId + ")"); String serverUrl = Config.YOUR\_SERVER\_URL; Map\<String, String\> params = new HashMap\<String, String\>(); params.put("regId", regId); params.put("name", name); params.put("email", email); long backoff = BACKOFF\_MILLI\_SECONDS + random.nextInt(1000); // Once GCM returns a registration id, we need to register on our server // As the server might be down, we will retry it a couple // times. for (int i = 1; i \<= MAX\_ATTEMPTS; i++) { Log.d(Config.TAG, "Attempt #" + i + " to register"); try { //Send Broadcast to Show message on screen displayMessageOnScreen(context, context.getString( R.string.server\_registering, i, MAX\_ATTEMPTS)); // Post registration values to web server post(serverUrl, params); .......... ....

And I guess Corona’s equivalent to “post(serverUrl, params);” would be “network.request(serverURL,“POST”,listener,params)” Which I’ve tried to send several times in different ways, but I always get the same error from the server.

[Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice: Undefined index: name in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 7 [Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice: Undefined index: email in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 8 [Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice: Undefined index: regId in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 11

My last attempt in Corona was this:

local commands\_json = { ["email"] = "test@test", ["name"] = system.getInfo("deviceID"), ["regId"] = DeviceID } local post\_body = json.encode( commands\_json ) local headers = {} headers["Content-Type"] = "application/json" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = post\_body params.progress = "download" network.request ( SERVER\_URL, "POST", networkListener, params )

This is the first time I’m using internet services, I’ve never sent or recieved anything before (or maybe just once many years ago) So I could be overlooking something really simple, so any help or suggestion is highly appreciated.

I don’t even know if I should be using this json thing, I’ve tried removing it (I don’t know what to do with the header in that case) but the same thing happens, I’m using it because it was there in the Pushwoosh example (which, again, didn’t work for me)