我开发了一个提醒应用程序,我使用了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 --pressing snooze and setting snooze time to 1mins
audio.stop()
print("**SNOOZED**")
forAlarm1 = timer.performWithDelay (60*1000, compareTime)
elseif 1==event.index then --pressing ok and setting the alarm to repeat mode
print("**ALARM SET TO REPEAT**")
audio.stop()
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)
有人可以告诉我如何修改我的代码才能在设备上运行它?
答案 0 :(得分:0)
我明白了。可以使用以下代码完成 local options = { alert =“警报!!!”, 徽章= 2, sound =“alarm.caf”, }
-- schedule using seconds from now
local notification = system.scheduleNotification( delay, options )
local listener = function( event )
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 )