×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.821 | Released: 23 May 2012, 2:01am | What's New | Download Now

system.scheduleNotification()

Description:

Schedule a local notification event to be delivered in the future.

Please see the corresponding blog tutorial for a walk-through of this feature.

Syntax:

1
2
system.scheduleNotification( secondsFromNow [, options] )
system.scheduleNotification( coordinatedUniversalTime [, options] )

Example:

-- Options for iOS 
local options = {
   alert = "Wake up!",
   badge = 2,
   sound = "alarm.caf",
   custom = { foo = "bar" }
}
 
-- schedule using seconds from now
local notification = system.scheduleNotification( 60, options )
 
-- schedule using UTC (Coordinated Universal Time)
local utcTime = os.date( "!*t", os.time() + 60 )
local notification = system.scheduleNotification( utcTime, options )
 
local listener = function( event )
   print( event.name ) -- ==> "notification"
   print( event.custom.foo ) -- ==> "bar"
end
 
Runtime:addEventListener( "notification", listener )

Parameters:

secondsFromNow
Number of seconds from now when the notification should be delivered.

coordinatedUniversalTime
Table containing same properties as returned by os.date( "!*t" ). A common error is to pass "*t" instead of "!*t" which incorrectly gives you the time in your current time zone.

options
Table specifying details about the notification to be delivered. The following keys can be specified:

  • custom Table that will be delivered in the notification.

In addition, the following iOS-specific options can be provided and (if specified) will be properties in the notification event that is to be delivered:

  • alert String of the message of the notification. If the application is not currently running, a system alert will display this message.
  • badge Number to set the badge count. 0 means no change.
  • sound String of the sound file to be played. This sound is only played if the app is not currently in the foreground. There are limitations on the kinds of sound that can be played. Consult Apple's documentation..
Returns:
Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    --
  • Windows:
    --
  • iOS:
    Build 2011.625
  • Android:
    --

Replies

jalemanyf
User offline. Last seen 1 week 4 days ago. Offline
Joined: 16 Jan 2011

I'm interested in this feature on Android platform. Please, could you tell me when it will be operative on android devices?

Thanks in advance

delwing
User offline. Last seen 3 weeks 6 days ago. Offline
Joined: 25 Feb 2011

I have problem with scheduling notifications using UTC time - it doesn't matter what date and time I use it sets notification to be scheduled in 0 seconds or somewhere in the past ( i can't check what actually happens). So all my notifications created using UTC time ( or local, or whatever ) are available as soon as I schedule them.
I am using current stable build.

Notifications set using seconds are working correctly - is there any limit for number of seconds set?

haraldconradi
User offline. Last seen 5 days 3 hours ago. Offline
Joined: 15 May 2011

I'd like this for Android as well - pushing alerts both on a schedule and based on in-app events (use cases).

Thanks.

dale
User offline. Last seen 4 weeks 17 hours ago. Offline
Joined: 22 Feb 2011

Just FYI, I had the instant-notification thing, too.

I couldn't get the examples to work either: until I removed the '!' from the os.date format string.

(The docs say to use "*t", which works; the example uses "!*t", which seems not to.)

spritestack
User offline. Last seen 1 week 6 hours ago. Offline
Joined: 12 Jan 2012

I think the info regarding badges is wrong... The badge parameter doesn't increment the number it sets it.

Would be good to see some clarification/confirmation from the Ansca staff, please..!

Greg

jonathanbeebe's picture
jonathanbeebe
User offline. Last seen 1 day 7 hours ago. Offline
Staff
Joined: 12 Apr 2011

@spritestack: I updated the documentation to be more clear, thanks.