Hey there.. I have an app that download an xml from internet and store this in a temporarydirectory...
my problem is... If I open my app without connection I get my error msg but if I open with internet connection and after that I exit my app, turn off my internet and re-open my app.. I don`t get the network error msg
it's seems that my .xml still there, but if I close my app the xml should be deleted no?
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 | -- in splashScene I have put this in my code: function onSystemEvent( event ) if "applicationSuspend" == event.type or "applicationExit" == event.type then local destDir = system.TemporaryDirectory -- where the file is stored local results, reason = os.remove( system.pathForFile( "noticias.xml", destDir ) ) if results then print( "file removed" ) else print( "file does not exist", reason ) end --> file does not exist apple.txt: No such file or directory end end Runtime:addEventListener( "system", onSystemEvent ) ------------------------------------------------------ ------------------------------------------------------ -- and in my menu.lua I have this code to download my xml: chegaConexao = function() local function networkListener( event ) if ( event.isError ) then local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then native.setActivityIndicator( false ) end end end -- Show alert with five buttons local alert = native.showAlert( "Error", "Network issue", { "OK" }, onComplete ) print ( "Network error - download failed" ) else print( "download xml" ) native.setActivityIndicator( false ) end print ( "RESPONSE: " .. event.response ) end network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener, "noticias.xml", system.TemporaryDirectory ) native.setActivityIndicator( true ) _G.carregarXMLs = false end if _G.carregarXMLs == true then timer.performWithDelay( 500, chegaConexao, 1 ) end -- and down there I have put this to control if app suspend: function onSystemEvent2( event ) if "applicationResume" == event.type then local function networkListener( event ) if ( event.isError ) then local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then native.setActivityIndicator( false ) end end end -- Show alert with five buttons local alert = native.showAlert( "Error", "Network issue", { "OK" }, onComplete ) print ( "Network error - download failed" ) else print( "download xml" ) native.setActivityIndicator( false ) end print ( "RESPONSE: " .. event.response ) end network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener, "noticias.xml", system.TemporaryDirectory ) native.setActivityIndicator( true ) end end Runtime:addEventListener( "system", onSystemEvent2 ) |