Push notifications

Thank you so much, Joshua.  I don’t know why I failed to find that function.  For my push notification on Google Play Android device, I’ll include system.cancelNotification() inside the onNotification event listener (which would be called after the app shows some visual prompt for the user to learn about a notification event – and I hope that would do the job.)

 

Thanks again!

Naomi

Happy to help Naomi!

Just so you know, I’ve taken a quick look at this and have discovered that system.cancelNotification() only removes local/scheduled notifications on iOS.  It does not remove remote/push notifications on iOS like how it works on Android.  I’ve  written up a bug report on our end to make it behave as expected.

Reversely, I’ve written up a bug report for Android to have it clear all notifications if you set the application badge number to zero to match the iOS behavior.

That sounds great, Joshua.  Thank you so much for the follow up.

For now, I’m using native.setProperty to reset the badge number for iOS devices and system.cancelNotification for Android.  I haven’t seen issues with this so far.

Thanks again.

Naomi

Joshua,

the custom data is missing again. I’ve only tested iOS. I can see in the forums that there are 5-7 threads about the issue, but no one from Corona pays any notice. To be able to send custom data with push notifications is an integral part of getting anything useful out of push notifications, thus it would be nice if you could get it fixed soon.

I’ve tried to send the custom data as both json and string, none of them works. When tracing the incoming data in the app, the custom key is in the payload, but it’s value is just an empty array - []

Sending this is not working:

aps = {

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:{“id”:“123”}

}

And sending this is not working:

aps = {

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:“123”

}

In the app, when doing a native.showAlert(“Push”, json.encode(event), {“OK”}) the message looks something like this:

{

   “type”: “remote”,

   “name”: “notification”,

   “applicationState”: “active”,

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:[]

}

I can confirm that the issue is also present on Android.

Some feedback would be appropriate…

Haakon,

I just re-tested our “GooglePushNotifications” sample app with release build #1076 and verified that it does work on Android.  That particular sample app has nested tables of various Lua types which we print to the Android log when the notification has been received.

I’m not sure why it’s not working for you.   I hate to ask this, but perhaps you are using an older daily build by mistake?  Or perhaps it is a JSON encoding issue?

Hi Joshua,

thanks for testing. I did a print of the json sent to Apple from our api, and it looks like this:

{“aps”:{“alert”:“Hello World”,“badge”:0,“sound”:“default”},“custom”:{“boolean”:true,“number”:123.456,“string”:“Custom data test”,“array”:[true,false,0,1,"",“This is a test.”],“table”:{“x”:1,“y”:2}}}

I can see that our custom is outside the aps, which might be why it’s acting weird. I’ll deploy a server update later which changes the payload to this:

{“aps”:{“alert”:“Hello World”,“custom”:{“boolean”:true,“number”:123.456,“string”:“Custom data test”,“array”:[true,false,0,1,"",“This is a test.”],“table”:{“x”:1,“y”:2}},“sound”:“notification.wav”}}

…and see if that helps. Thanks for pointing me to the sample app, I did not know it contained the payload to send. Will post an update here when I’ve tested.

Happy to help Haakon.

Yeah, that sample app has proved useful in testing Corona’s deserialization of JSON and Android intent objects into Lua by testing every value type and hierarchy of tables.  The only JSON value we cannot provide into Lua is “null”, but that is a Lua table limitation because Lua removes table entries having “nil” values.

Joshua,

the custom data is missing again. I’ve only tested iOS. I can see in the forums that there are 5-7 threads about the issue, but no one from Corona pays any notice. To be able to send custom data with push notifications is an integral part of getting anything useful out of push notifications, thus it would be nice if you could get it fixed soon.

I’ve tried to send the custom data as both json and string, none of them works. When tracing the incoming data in the app, the custom key is in the payload, but it’s value is just an empty array - []

Sending this is not working:

aps = {

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:{“id”:“123”}

}

And sending this is not working:

aps = {

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:“123”

}

In the app, when doing a native.showAlert(“Push”, json.encode(event), {“OK”}) the message looks something like this:

{

   “type”: “remote”,

   “name”: “notification”,

   “applicationState”: “active”,

   “alert”:“test”,

   “badge”:0,

   “sound”:“default”,

   “custom”:[]

}

I can confirm that the issue is also present on Android.

Hi,

Moving the custom payload to the same level as alert made the difference!

However, if we send up a string and not a table as the custom value, the app crashes. I think it should be possible to do this:

var payload = {

  alert: “The message”,

  custom: “my custom string”

}

but that makes the ios app crash without warning. It just exits. You should do a type check when parsing the incoming custom payload and not take it for granted that the custom data is a table…

This is on ios, btw. Haven’t tested Android yet.

Haakon,

The notification’s “event.custom” field only supports tables.  That is by design as documented here…

http://docs.coronalabs.com/api/event/notification/custom.html

Although, it shouldn’t crash.  So, I’ll write that up as a bug.

I know Android won’t crash.  It’ll ignore the custom field if it’s not a table or an array.

Some feedback would be appropriate…

Haakon,

I just re-tested our “GooglePushNotifications” sample app with release build #1076 and verified that it does work on Android.  That particular sample app has nested tables of various Lua types which we print to the Android log when the notification has been received.

I’m not sure why it’s not working for you.   I hate to ask this, but perhaps you are using an older daily build by mistake?  Or perhaps it is a JSON encoding issue?

Hi Joshua,

thanks for testing. I did a print of the json sent to Apple from our api, and it looks like this:

{“aps”:{“alert”:“Hello World”,“badge”:0,“sound”:“default”},“custom”:{“boolean”:true,“number”:123.456,“string”:“Custom data test”,“array”:[true,false,0,1,"",“This is a test.”],“table”:{“x”:1,“y”:2}}}

I can see that our custom is outside the aps, which might be why it’s acting weird. I’ll deploy a server update later which changes the payload to this:

{“aps”:{“alert”:“Hello World”,“custom”:{“boolean”:true,“number”:123.456,“string”:“Custom data test”,“array”:[true,false,0,1,"",“This is a test.”],“table”:{“x”:1,“y”:2}},“sound”:“notification.wav”}}

…and see if that helps. Thanks for pointing me to the sample app, I did not know it contained the payload to send. Will post an update here when I’ve tested.

Happy to help Haakon.

Yeah, that sample app has proved useful in testing Corona’s deserialization of JSON and Android intent objects into Lua by testing every value type and hierarchy of tables.  The only JSON value we cannot provide into Lua is “null”, but that is a Lua table limitation because Lua removes table entries having “nil” values.

Hi,

Moving the custom payload to the same level as alert made the difference!

However, if we send up a string and not a table as the custom value, the app crashes. I think it should be possible to do this:

var payload = {

  alert: “The message”,

  custom: “my custom string”

}

but that makes the ios app crash without warning. It just exits. You should do a type check when parsing the incoming custom payload and not take it for granted that the custom data is a table…

This is on ios, btw. Haven’t tested Android yet.

Haakon,

The notification’s “event.custom” field only supports tables.  That is by design as documented here…

http://docs.coronalabs.com/api/event/notification/custom.html

Although, it shouldn’t crash.  So, I’ll write that up as a bug.

I know Android won’t crash.  It’ll ignore the custom field if it’s not a table or an array.