在Corona中安排通知的调度

我开发了一个提醒应用程序,我使用 timer.performWithDelay 函数调用其中指定任务的功能。它在模拟器上运行得很好。我想在设备上运行它,为此我需要使用 system.scheduleNotification。 我无法理解如何使用它并在模拟器中检查。我正在分享我编写的代码。

local function onComplete( event )
print( "index => ".. event.index .. " action => " .. event.action )

local action = event.action
if "clicked" == event.action then

if 2 == event.index then --按下午觉,将小睡时间设置为1分钟
audio.stop()
print("**SNOOZED**")
forAlarm1 = timer.performWithDelay (60*1000, compareTime)

elseif 1==event.index then --按下确定并设置闹钟为重复模式
print("**ALARM SET TO REPEAT**")
audio.stop()
end
end

end

function compareTime()
print("CompareTime is called")
timer.performWithDelay (7*24*3600*1000, compareTime)
audio.play(alarm)
local alert = native.showAlert( "Garbage Collection Reminder", "It's Time", { "OK",     "SNOOZE" },onComplete)

end

forAlarm = timer.performWithDelay (delay*1000, compareTime)

有人能告诉我如何修改我的代码以在设备上运行吗???

点赞
用户1897639
用户1897639

我想到了,可以使用以下代码实现:

local options = {
    alert = "Alert!!!",
    badge = 2,
    sound = "alarm.caf",
}

-- 使用延迟秒数进行调度
local notification = system.scheduleNotification(delay, options)

local listener = function(event)
    -- 每 7 天再次进行调度
    local notification = system.scheduleNotification(7 * 24 * 3600 * 1000, options)
    local alert = native.showAlert("Garbage Collection Reminder", "It's Time", {"OK", "SNOOZE"}, onComplete)
end

-- 添加通知监听
Runtime:addEventListener("notification", listener)
2013-01-31 07:24:14