What do Corona expect from GCM for notifications?

Hi,

I have been trying to implement notifications and I recieve them but there is no message, alert, or custom.

They are always empty.

My server is written in C# and as mentioned the notifications are recieved by the app but they are empty.

I/Corona ( 5039): \*\*\*\* REMOTE NOTIFICATION \*\*\*\* I/Corona ( 5039): type remote I/Corona ( 5039): name notification I/Corona ( 5039): custom table: 0x7790c8c0 I/Corona ( 5039): alert I/Corona ( 5039): applicationState active I/Corona ( 5039): \*\*\*\* CUSTOM \*\*\*\*

(There is nothing when I loop over event.custom)

Right now the string that my server sends to GCM looks like this:

"custom=hello&alert=tomas&collapse\_key=score\_update&time\_to\_live=108&delay\_while\_idle=1&data.message=" + message + "&data.time=" + System.DateTime.Now.ToString() + "&registration\_id=" + this.DeviceID.ToString() + "";

But I have been trying several forms including the one that I found on several pages:

{ alert:"An alert with custom data", badge: 1, sound: "default", custom: { foo: "bar" } }

I see that more people have had problem with this:

http://forums.coronalabs.com/topic/48026-unable-to-send-custom-data-to-ios-2014/

I have read the instructions several time but I might be missing something:

http://docs.coronalabs.com/guide/events/appNotification/index.html#notification-data

I would prefer not to use a 3rd party due to sensitive information.

Best regards,

Tomas

Have a look at sample project “Notifications/GooglePushNotifications” that is included with the Corona Simulator.  That sample app pushes a notification to itself via GCM.  It shows you how to set up the JSON for the push notification for setting the alert message, custom sound file, and how to add custom data of various Lua types (ie: Boolean, number, string, arrays, and tables).  In particular, have a look at the “main.lua” file’s sendNotification() and onTap() functions to see how the HTTP message is formatted.

I recommend that you start with the simple case and make your GCM push notifications work with this sample project first.  This way you can verify that you have everything set up with Google correctly first.  The second step would be push notifications from your server.

I’ll check it out. The thing is that I do recieve notifications when my server sends them so I don’t think that is the problem, probably more like how they should be formatted but I’ll check it out to see what I can get from it.

I’m sure you’re sending the message correctly.  The issue is most likely with your JSON.  Google does not actually define the “alert” and “custom” fields in JSON.  This is a Corona specific thing because you need to tell our Corona library how to handle the notification.  If you format the JSON as shown in the sample project, then this issue should be solved.

I can see what your code is doing wrong.  The “alert” and “custom” fields that you have need to be under a “data” table.  That is, they should not be at the same level as the “registration_ids” field.

Also, the “badge” field will be ignored on Android since app badges are not supported on that platform.

Hi Joshua,

I did as you said and I got it to work. I thought I was all badass and all and that I didn’t any of the samples but sometimes, going back to the basic, makes things more clearer!

Best regards,

Tomas

Have a look at sample project “Notifications/GooglePushNotifications” that is included with the Corona Simulator.  That sample app pushes a notification to itself via GCM.  It shows you how to set up the JSON for the push notification for setting the alert message, custom sound file, and how to add custom data of various Lua types (ie: Boolean, number, string, arrays, and tables).  In particular, have a look at the “main.lua” file’s sendNotification() and onTap() functions to see how the HTTP message is formatted.

I recommend that you start with the simple case and make your GCM push notifications work with this sample project first.  This way you can verify that you have everything set up with Google correctly first.  The second step would be push notifications from your server.

I’ll check it out. The thing is that I do recieve notifications when my server sends them so I don’t think that is the problem, probably more like how they should be formatted but I’ll check it out to see what I can get from it.

I’m sure you’re sending the message correctly.  The issue is most likely with your JSON.  Google does not actually define the “alert” and “custom” fields in JSON.  This is a Corona specific thing because you need to tell our Corona library how to handle the notification.  If you format the JSON as shown in the sample project, then this issue should be solved.

I can see what your code is doing wrong.  The “alert” and “custom” fields that you have need to be under a “data” table.  That is, they should not be at the same level as the “registration_ids” field.

Also, the “badge” field will be ignored on Android since app badges are not supported on that platform.

Hi Joshua,

I did as you said and I got it to work. I thought I was all badass and all and that I didn’t any of the samples but sometimes, going back to the basic, makes things more clearer!

Best regards,

Tomas