Warnings related to "applicationIconBadgeNumber" (Local Notifications)

Hello,

I’m using local notifications in one of my iOS-only apps. There is only one event within the app (which occurs once every few hours) that I notify the user about and hence I don’t have the need to use a badge number greater than 1 at any given time. So while scheduling a local notification I just use a badge number of 1. This works as intended.

When the notification arrives, assuming the app is suspended, the user can do one of two things to start the app –

  1. Tap on the notification.

  2. Tap on the app icon itself.

When the app is started, the badge number must of course be decremented. To handle scenario 1, I’ve setup a Runtime notification listener in main.lua. Scenario 2 is handled via the Runtime system event listener in the lua files of the relevant scenes. The code for these goes like this –

-- main.lua local function onNotification ( event ) if ( event.type == "local" ) then local badgeNum = native.getProperty ( "applicationIconBadgeNumber" ) if badgeNum ~= nil and badgeNum \> 0 then badgeNum = badgeNum - 1 native.setProperty ( "applicationIconBadgeNumber", badgeNum ) end end end Runtime : addEventListener ( "notification", onNotification ) if launchArgs and launchArgs.notification then onNotification ( launchArgs.notification ) end

-- scene.lua local function onSystemEvent ( event ) local eventType = event.type if ( eventType == "applicationStart" ) then -- Do something elseif ( eventType == "applicationSuspend" ) then -- Do something elseif ( eventType == "applicationResume" ) then local badgeNum = native.getProperty ( "applicationIconBadgeNumber" ) if badgeNum ~= nil and badgeNum \> 0 then badgeNum = badgeNum - 1 native.setProperty ( "applicationIconBadgeNumber", badgeNum ) end end return true end Runtime : addEventListener ( "system", onSystemEvent )

While the above code works fine on all iOS versions, while building, I get the following warning –
 

WARNING: native.getProperty() was given unknown key: applicationIconBadgeNumber

To avoid using the native.getProperty function in the above badge reduction code, I even tried replacing it with this –

native.setProperty ( "applicationIconBadgeNumber", 0 )

Instead, I now get the following warning while building –

WARNING: native.setProperty() was given an invalid selector: applicationIconBadgeNumber

The above warnings have no effect on the actual device builds itself. Local notifications work fine in the app on all iOS 6+ devices. It’s just that the warnings persist in the console while building and in fact, even when I just fire up the Corona simulator. Some more specifics –

Corona Daily Build - 2015.2728

Target iOS SDK - 9.0

This isn’t really a bug, so I don’t want to file one. But the warnings are bothering me and it would be great if our engineers could have a quick look at this.

Hi @Prathap Murthy,

Just to clarify, by setting it to “0”, I imagine that you effectively want to clear the badge number icon, because it’s not possible or practical to show a badge number with “0” on it. In that case, I think you should simply cancel the notification outright… that will clear it.

https://docs.coronalabs.com/plugin/notifications/cancelNotification.html

Based on your observations, however, I should update our documentation that the value for .setProperty() should be an integer > 0. :slight_smile:

Best regards,

Brent

Thanks for that, Brent. This documentation in particular needs to be updated then (and of course, others that offer the same advice).

But that’s not the point I was making. Corona SDK comes with a sample project for local notifications (CoronaSDK -> SampleCode -> System -> LocalNotifications). If you run it in the simulator, and tap the last button ‘Set Badge (0)’, you will get this warning –

Oct 05 06:15:57.931: WARNING: /Applications/CoronaSDK/SampleCode/System/LocalNotifications/main.lua:164: native.setProperty() was given an invalid selector: applicationIconBadgeNumber

Somehow, native.getProperty and native.setProperty functions seem to frown upon the key ‘applicationIconBadgeNumber’. I just want to find out why.

Hi @Prathap Murthy,

Just to clarify, by setting it to “0”, I imagine that you effectively want to clear the badge number icon, because it’s not possible or practical to show a badge number with “0” on it. In that case, I think you should simply cancel the notification outright… that will clear it.

https://docs.coronalabs.com/plugin/notifications/cancelNotification.html

Based on your observations, however, I should update our documentation that the value for .setProperty() should be an integer > 0. :slight_smile:

Best regards,

Brent

Thanks for that, Brent. This documentation in particular needs to be updated then (and of course, others that offer the same advice).

But that’s not the point I was making. Corona SDK comes with a sample project for local notifications (CoronaSDK -> SampleCode -> System -> LocalNotifications). If you run it in the simulator, and tap the last button ‘Set Badge (0)’, you will get this warning –

Oct 05 06:15:57.931: WARNING: /Applications/CoronaSDK/SampleCode/System/LocalNotifications/main.lua:164: native.setProperty() was given an invalid selector: applicationIconBadgeNumber

Somehow, native.getProperty and native.setProperty functions seem to frown upon the key ‘applicationIconBadgeNumber’. I just want to find out why.