I have a local notification alarm, I have put the data in the table, and created a loop. I am using v2015.4.6.
My problems are:
* When I built the App, on its first run, the App will show a blank notification
* some of the notification/s will repeat itself at the same time
* alarm tone does not ring
But it works well in the simulator using timer.performWithDelay()
Here is my code
local hourLog = {} local minuteLog = {} local msgLog = {} local SecondsToAdd local date = os.date( "\*t" ) local DAYSEC = 24\*3600 local TimeNow local AlarmTime local badge\_count = 0 alarmTime = {} alarmTime = { {6,0, "It's time to drink 2 glasses of water"}, {6,30, "BREAKFAST: Limit your water intake while eating; it will dilute your digestive enzymes"}, {8,30, "It's time to drink 1 glass of water"}, {9,30, "It's time to drink 1 glass of water"}, {10,30, "It's time to drink 2 glasses of water"}, {12,0, "LUNCH: Limit your water intake while eating; it will dilute your digestive enzymes"}, {13,30, "It's time to drink 1 glass of water"}, {14,30, "It's time to drink 1 glass of water"}, {15,30, "It's time to drink 1 glass of water"}, {16,30, "It's time to drink 1 glass of water"}, {18,0, "If you want to reduce some weight, you can omit your dinner; but you have to sleep before 10 pm or earlier you will be hungry"}, {19,0, "It's time to drink 1 glass of water"}, } for i = 1, #alarmTime do msgLog[i] = alarmTime[i][3] hourLog[i] = alarmTime[i][1] minuteLog[i] = alarmTime[i][2] local TimeNow = (date.hour \* 3600) + (date.min \* 60) + date.sec local AlarmTime = ( hourLog[i]\* 3600) + (minuteLog[i] \* 60) if TimeNow \< AlarmTime then SecondsToAdd = AlarmTime - TimeNow else SecondsToAdd = DAYSEC - TimeNow SecondsToAdd = SecondsToAdd + AlarmTime end --## for device options local alertOption = { alert = msgLog[i], badge = badge\_count + 1, sound = "IWON\_alarm.mp3", } local notification = system.scheduleNotification( SecondsToAdd, alertOption ) --[[for simulator local listener = function (event) local alert = native.showAlert("Alert",msgLog[i],{"OK"}, onComplete ) end --forTimer = timer.performWithDelay(SecondsToAdd\*1000, listener)]] end
* I want the notification to display on the specific time (not repeating).
* The alarm is on a daily basis, will I need to reschedule it?
* Or could you suggest a better way to do it?
Thanks in advance =)