Push notifications

@Josh: I for one cannot see any custom data in iOS pushes. My payload is arranged like this (PHP):

[php]
$body[“aps”] = array(
“sound” => “default”,
“alert” => $message,
“custom” => array(
“hello” => “Hello”,
),
);
$body[“world”] = “World”; // Suggested by some forum posting, but does not work either
[/php]

The notification arrives on iPhone like this:

[lua]notification = {
type = “remote”,
name = “notification”,
custom = {
},
sound = “default”,
alert = “This is your wake-up call”,
applicationState = “inactive”, – doesn’t work for active state either
}[/lua]

PS! Looking forward to the notification fix in the next build. [import]uid: 73434 topic_id: 31525 reply_id: 136435[/import]

I’ll have someone investigate this on iOS late next week.
(Most of our team is out during the new years holidays.)

Oh and Android does not support application badge numbers. However, Android does support attaching numbers to individual notifications in the status bar. It’s not quite the same thing since a push notification would typically represent only 1 item.

The only thing that I can think of is for us to create a special status bar notification to display the app badge number on Android, which is not removed when the user taps on it. It would only be removed when you set the badge number back to zero. Kind of like how it works with the standard Android mail app. But in this case, you probably don’t want to see the individual notifications under the app’s main status bar notification which displays the badge number… so perhaps we would have to add an option to the push notification’s JSON to tell Corona to not put it into the status bar and only update the app badge number when received (I hope that made sense). In any case, we’re talking about adding special handling that differs with iOS, but perhaps that can’t be helped.

In any case, those are my thoughts. Please feel free to let me know how you think it should work. [import]uid: 32256 topic_id: 31525 reply_id: 136823[/import]

Olav,

It looks like you are sending the custom data correctly to me. The only restriction we have on custom data is that it must be a table. At least at the root level… and you’re sending it as a table.

I’ll have someone on my end investigate this. Also, if you don’t mind, I suggest that you write this up as a bug report so that it’ll get on our tech-support queue and so that you’ll be notified via e-mail when it gets resolved. You can do so by clicking the “Report a Bug” link at the top of this web page.

In the mean-time, the “event.custom” data definitely works on Android. I’ve tested this for myself. If you look at sample app “Notifications/GooglePushNotifications” that is included with the Corona SDK, notice that it sends all kinds of data in one shot (ie: table, boolean, number, string, nested array, nested table, mixed types within a table/array). We did this to demonstrate its capabilities and for our own testing. So, please feel free to use custom data on Android.

By the way, daily build #944 is available now. This version will raise the notification event immediately if your Android app is active and in the foreground, just like iOS. [import]uid: 32256 topic_id: 31525 reply_id: 136473[/import]

I’m not that familiar with Android User Interface conventions, so I’ll leave this one to someone else’s opinion.

In the meantime, being able to set iOS badge count even while the app is suspended would make a huge difference in communicating app activity to users.

I suppose there are two ways of doing this:

a) Push server calculates badge value, sends it to the app through the “event.badge” value, and Corona automatically sets the badge count.

b) Implement an event listener which can trigger Lua code when receiving a push while the app is suspended, so that the app can calculate the badge value based on various data such as unread messages, disregarding “event.badge” completely.

Each has its pros and cons. Which one do you see as more preferable (and easy to implement)?
[import]uid: 73434 topic_id: 31525 reply_id: 136880[/import]

@Josh: Brilliant! Android now catches the push even from within the app. It’s very reassuring to see you guys handling issues so quickly.

About the “custom” field: Yes, it works on Android. But it never has worked on iPhone (I tried this months ago too). I filed a bug report like you requested. Please keep me updated (here, or in the bug report system if it keeps the reporter updated by e-mail).

[import]uid: 73434 topic_id: 31525 reply_id: 136503[/import]

Yeah, I reported that custom data was missing in ios push notifications almost a year ago, but I guess my score was low already then since nothing was ever done with it… :slight_smile: Hope your karma is better than mine, Olav!

Just a hint to those of you implementing push on Android. We’ve had a RUSH of support tickets since releasing in in MindFeud. There’s nowhere to control push settings per app in the Android OS, so take the time to implement your own in-app settings to allow your users to turn on/off push completely, and the choice between banners only or banner and sound. We’re releasing that tomorrow! :O) [import]uid: 21746 topic_id: 31525 reply_id: 136504[/import]

Olav, Haakon,

The “event.custom” data issue on iOS is being investigated by someone now.
I had a quick look at our bug database and we do indeed have several outstanding bug reports regarding “event.custom” data on iOS. Admittedly, we dropped the ball on this issue because some of us (including me) thought it was already resolved. I apologize for that. In any case, we’re looking into resolving this issue now.
[import]uid: 32256 topic_id: 31525 reply_id: 136506[/import]

Everyone,

We’ve just updated Corona for iOS to support custom data from push notifications. This change will be made available in daily build #995, tomorrow. [import]uid: 32256 topic_id: 31525 reply_id: 136531[/import]

@Josh: I can confirm that the custom fields now work on iPhone. Great work, man!

I have a final question about pushes: Shouldn’t event.badge set the application badge directly? This has never worked. This means the end user never gets any indication that something has happened in the app before he actually goes into the app, and the badge is set manually with native.setProperty(“applicationIconBadgeNumber”, badge), and then it’s sort of too late. If setting the badge directly is a quick fix, I would really appreciate to see it in an upcoming build.
[import]uid: 73434 topic_id: 31525 reply_id: 136666[/import]

>> I can confirm that the custom fields now work on iPhone. Great work, man!

Great to hear! All thanks goes to Perry, our new VP of Engineering. I merely raised the issue and pointed out what needed to be done. :slight_smile:

>> Shouldn’t event.badge set the application badge directly?

Our blog post about iOS remote notifications (see the below link) suggests that it can. I believe you have to add the “badge” setting to your “config.lua” file as described by that blog entry to make this work. If the blog’s instructions still don’t work for you, then I can have someone investigate this late next week.
http://www.coronalabs.com/blog/2011/12/21/push-notifications-for-ios-in-corona-sdk/
[import]uid: 32256 topic_id: 31525 reply_id: 136741[/import]

According to my tests, this is the current status:

  1. iPhone:
  • YES: native.setProperty(“applicationIconBadgeNumber”, badge)
  • NO: event.badge
  1. Android:
  • NO: native.setProperty(“applicationIconBadgeNumber”, badge)
  • NO: event.badge

If you plan to fix this, make sure it works whether the app is running or suspended.

[lua]notification = {
iphone = {
types = {
“badge”, “sound”, “alert”,
},
},
},[/lua]

[php]
$body[“aps”] = array(
“sound” => “default”,
“alert” => $message,
“badge” => 7,
);
[/php]
[import]uid: 73434 topic_id: 31525 reply_id: 136749[/import]

I’ll have someone investigate this on iOS late next week.
(Most of our team is out during the new years holidays.)

Oh and Android does not support application badge numbers. However, Android does support attaching numbers to individual notifications in the status bar. It’s not quite the same thing since a push notification would typically represent only 1 item.

The only thing that I can think of is for us to create a special status bar notification to display the app badge number on Android, which is not removed when the user taps on it. It would only be removed when you set the badge number back to zero. Kind of like how it works with the standard Android mail app. But in this case, you probably don’t want to see the individual notifications under the app’s main status bar notification which displays the badge number… so perhaps we would have to add an option to the push notification’s JSON to tell Corona to not put it into the status bar and only update the app badge number when received (I hope that made sense). In any case, we’re talking about adding special handling that differs with iOS, but perhaps that can’t be helped.

In any case, those are my thoughts. Please feel free to let me know how you think it should work. [import]uid: 32256 topic_id: 31525 reply_id: 136823[/import]

I’m not that familiar with Android User Interface conventions, so I’ll leave this one to someone else’s opinion.

In the meantime, being able to set iOS badge count even while the app is suspended would make a huge difference in communicating app activity to users.

I suppose there are two ways of doing this:

a) Push server calculates badge value, sends it to the app through the “event.badge” value, and Corona automatically sets the badge count.

b) Implement an event listener which can trigger Lua code when receiving a push while the app is suspended, so that the app can calculate the badge value based on various data such as unread messages, disregarding “event.badge” completely.

Each has its pros and cons. Which one do you see as more preferable (and easy to implement)?
[import]uid: 73434 topic_id: 31525 reply_id: 136880[/import]

@Josh: Any news on getting iOS to update the badge count even when the app is suspended?

To answer my own question: It must be possible to update the badge when the app is *not running* too (not just when it is suspended), so that rules out running a local Lua script upon receiving the push. The push server must be the one to decide the badge count, right?

I classify this feature as quite important, as it drives users into the app, which with today’s situation will never happen if the app is not running, in the foreground even, on the device.
[import]uid: 73434 topic_id: 31525 reply_id: 137929[/import]

Sorry about not getting back to you on this.

We tested this last week and we were not able to reproduce this issue. We were able to successfully update the app badge number via a push notification without issue. We even tried your exact PHP script up above and your “config.lua” settings and it still worked for us. We had 2 different people test it in our office just in case and it worked for both of them. So, it doesn’t sound like a problem on our end.

Now, we did notice that if you enable “newsstand” support in your “config.lua” file (which is not something we’ve documented), then the app badge number will not update, but that appears to be by Apple’s design because updates will be shown in your News Stand app instead.

I hate to ask this, but are you sure you do not have badge numbers disabled for you app under Settings on your iOS device?
[import]uid: 32256 topic_id: 31525 reply_id: 137933[/import]

Aww! The “newsstand” value was the culprit. Of all the strange quirks… Dunno why it was even there in the first place. Probably came with some old example code or something. Oh well, live and learn! Thanks for clearing this up, JQ!
[import]uid: 73434 topic_id: 31525 reply_id: 137944[/import]

Great! I’m glad it’s working for your now! :slight_smile: [import]uid: 32256 topic_id: 31525 reply_id: 137955[/import]

@Josh: Any news on getting iOS to update the badge count even when the app is suspended?

To answer my own question: It must be possible to update the badge when the app is *not running* too (not just when it is suspended), so that rules out running a local Lua script upon receiving the push. The push server must be the one to decide the badge count, right?

I classify this feature as quite important, as it drives users into the app, which with today’s situation will never happen if the app is not running, in the foreground even, on the device.
[import]uid: 73434 topic_id: 31525 reply_id: 137929[/import]

Sorry about not getting back to you on this.

We tested this last week and we were not able to reproduce this issue. We were able to successfully update the app badge number via a push notification without issue. We even tried your exact PHP script up above and your “config.lua” settings and it still worked for us. We had 2 different people test it in our office just in case and it worked for both of them. So, it doesn’t sound like a problem on our end.

Now, we did notice that if you enable “newsstand” support in your “config.lua” file (which is not something we’ve documented), then the app badge number will not update, but that appears to be by Apple’s design because updates will be shown in your News Stand app instead.

I hate to ask this, but are you sure you do not have badge numbers disabled for you app under Settings on your iOS device?
[import]uid: 32256 topic_id: 31525 reply_id: 137933[/import]

Aww! The “newsstand” value was the culprit. Of all the strange quirks… Dunno why it was even there in the first place. Probably came with some old example code or something. Oh well, live and learn! Thanks for clearing this up, JQ!
[import]uid: 73434 topic_id: 31525 reply_id: 137944[/import]