2014-01-06 62 views
0

如何在我的應用程序中實現每日本地通知?因此,首先我需要在14:00登記第一次當地通知,然後每天14:00登記通知。如何在特定時間每天註冊本地通知?

用戶可以在應用程序的設置中更改此時間。

如何做到這一點?

回答

1

您需要處理您的最終的notifcations,而是使每個人一天countsdown一定時間的計時器,你需要做這樣的事情:

local targetDate = os.time{ year=2014, month=11, day=8, hour=0, sec=0 } -- Get the date that you want to count down to, in seconds 
local text = false 

local function enterFrame(event) 
    if text then text:removeSelf() end -- Everyframe, remove the old text object 
    local timeRemaining = (targetDate-os.time()) -- Take the difference between the target time and the current time 
    local days = timeRemaining/86400  -- get the number of days left by dividing the remaining seconds by the number of seconds in a day 
    local hours = days%1 * 24   -- get the number of hours left by multiplying the remainder by the number hours in a day 
    local minutes = hours%1 * 60   -- get the number of minutes by multiplying the remainder by the number of minutes in an hour 
    local seconds = math.floor(minutes%1 * 60 + 0.5) -- multiply the remainder one more time by the number of seconds in a minute, and round to the nearest second. 
    -- make a new text object to display all the info 
    text = display.newText("Will be available in "..math.floor(days).." days "..math.floor(hours).." hrs "..math.floor(minutes).." mins "..seconds.." secs ", 25, 140) 
end 

Runtime:addEventListener("enterFrame", enterFrame) 

你可以重新調整你的代碼與您的項目一起工作,但您需要使用操作系統時間並對每個變量進行一定的計算以獲得時間。祝你好運。

+0

謝謝!在** notificationListener **中,我應該調用:'localNotif = system.scheduleNotification(86400,reminderOptions)' – Romowski