So my problem is... as corona don't support push notification yet I'm trying to do my own "push notification".
I download an XML and check the current date and mouth to give the notification. But for some reason it don't work =S
if someone knows what i'm doing wrong...
I have this in my main.lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | saveit = require( "saveit" ) -- Save/Loading no arquivo .txt local function resumeStart() local path = system.pathForFile( "save1.txt", system.DocumentsDirectory ) local file = io.open( path, "r" ) if file then print("Loading our data...") local contents = file:read( "*a" ) -- Loads our data local prevState = explode(", ", contents) _G.dia = prevState[1] _G.mes = prevState[2] io.close( file ) else _G.dia = 9 -------------- _G.mes = 11 -------------- end end -- Separates the variables into a table local function onSystemEvent( event ) if( event.type == "applicationExit" ) then local path = system.pathForFile( "save1.txt", system.DocumentsDirectory ) local file = io.open( path, "w+b" ) -- Creates the file where we save our data file:write( _G.dia ..", ".. _G.mes ) io.close( file ) end end -- Saves our data function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function() return string.find(str,div,pos,true) end do table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider return arr end local function comeca() -- start and resume from previous state, if any resumeStart() Runtime:addEventListener( "system", onSystemEvent ) end -- ========================================= FIM ============================================= -- comeca() -- TESTE DE NOTIFICACOES -- NOTIFICATIONS local options = { alert = "Nova Festa!", badge = 1, sound = "wee.wav", custom = { anythingYouWant = "Festa X" } } local date = os.date( "*t" ) -- returns table of date & time values checaNotificacoes = function() if date.day == _G.dia and date.month == _G.mes then print( "notificacao ativada" ) launchArgs = system.scheduleNotification( 0.1, options ) Runtime:removeEventListener( "enterFrame", checaNotificacoes ) else tiraBadge = system.scheduleNotification( 0.1, { badge = -1 } ) end end function notificationListener( event ) -- display alert that shows the event name and type: function clickOkNotificacao( event ) if "clicked" == event.action then bys = event.index if 1 == bys then --system.cancelNotification( launchArgs ) end end end native.showAlert( event.alert, event.custom.anythingYouWant, { "OK" }, clickOkNotificacao ) end -- Listen for notification events: Runtime:addEventListener( "notification", notificationListener ) Runtime:addEventListener( "enterFrame", checaNotificacoes ) |
maybe beebe knows anything about it?
What I would recommend is inserting print statements to make sure that things are downloading correctly, and you are receiving the proper conditions that's needed to trigger your notification.
Then, I'd go through this blog post line-by-line to make sure you're scheduling and handling notifications properly.
hey beebe, How can I constant check if I can activate my checkNotifications function?
If I use " Runtime:addEventListener( "enterFrame", checkNotifications ) " it will lag my app right?
I'm tried to use " timer.performWithDelay " but every time that I suspend the app, the timer close too
any idea?
thanks