Local Notification

Hello,

I went through documentation here http://docs.coronalabs.com/guide/events/appNotification/index.html but I still struggle with implementing local notification. The only thing I need is a notification to show up every day at 6PM. And then when user opens the app then the badge icon will change from “1” to “0”. I can manage to show notifications but no matter what I do the badge icon always shows “1”. Can anyone guide me? Thank you.

This is my code:

-- Get the app's launch arguments in case it was started when the user tapped on a notification. local launchArgs = system.cancelNotification( notificationID ) --current date and time local date = os.date( "\*t" ) local hour = date.hour local minute = date.min local seconds = (24+18-hour)\*3600 - (minute\*60) --this should calculate seconds remaining till next day's 6PM -- Set up notification options. local options = { alert = "The app is waiting for You!", badge = 1, } -- Schedule a notification to occur next day at 6PM from now. local notificationId = system.scheduleNotification( seconds, options ) -- Schedule a notification using current time zone local Time = os.date( "\*t", os.time() + seconds ) notificationId = system.scheduleNotification( Time, options ) -- Listen for notifications. local onNotification = function( event ) if ( event.type == "local" ) then --handle the local notification badge\_num = 0 native.setProperty( "applicationIconBadgeNumber", badge\_num ) end end Runtime:addEventListener( "notification", onNotification ) -- The app's launch arguments will provide a notification event if this app was started -- when the user tapped on a notification. You must call the notification listener manually. if launchArgs and launchArgs.notification then onNotification( launchArgs.notification ) end

Hi @radim.simanek,

Is the application reaching the point where you set “badge_num” and then call “native.setProperty()”? Can you put a print() statement in there for testing and confirm that the app reaches that point?

Best regards,

Brent

I put a print statement there and no output. Seems like it’s not reaching that point. I’m on iOS8. I’ll try to play with it a bit more.

Hi @radim.simanek,

Is the application reaching the point where you set “badge_num” and then call “native.setProperty()”? Can you put a print() statement in there for testing and confirm that the app reaches that point?

Best regards,

Brent

I put a print statement there and no output. Seems like it’s not reaching that point. I’m on iOS8. I’ll try to play with it a bit more.