Corona SDK - 重复通知

Corona SDK - repeated notifications

我在 Corona 中有一些代码可以在应用程序启动 60 秒后触发通知。它看起来像这样:

local notifications = require( "plugin.notifications" )
-- Set up notification options
local notificationOptions = {
    alert = "Wake up!",
    badge = 2,
    sound = "alarm.caf",
    custom = { foo = "bar" }
}
local notification1 = notifications.scheduleNotification( 60, notificationOptions )

但是,我找不到如何使它成为周期性的。例如,每分钟一次、每小时一次、每天特定时间一次等。

知道怎么做吗?

谢谢。

此致, 塞尔维亚语

我认为你需要运行循环执行此操作,像这样(每分钟一小时):

   local notificationTable = []    
   for i=1,60 do
     local time = 60*i
     local handle = notifications.scheduleNotification( time, notificationOptions )
     notificationTable[time] = handle 
   end

注意:代码未经测试,对于数组,可能还有其他更好的方法,但这应该能让您有所了解。 对于特定时间,您需要使用 UTC 时间而不是从现在开始的秒数。

A table indicating the Coordinated Universal Time (UTC) at which to deliver the notification. This table should contain the same properties as returned by os.date( "!*t" ). Note that a common pitfall is to pass "*t" instead of "!*t" which results in a time given in your current time zone instead of a UTC time.

https://docs.coronalabs.com/daily/plugin/notifications/scheduleNotification.html

希望对您有所帮助。