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 –
-
Tap on the notification.
-
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.