network.download problem ANSCA HELP!

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 )  
  

When I open my app, the “noticias.xml” are donwloaded but if I change the XML in my website and re-open my app, the XML don’t change… I need turn off my internet after that turn on to network.download work and download the new XML

is like the network.download are storing this xml in a tmp on device and take this instead of download a new one from my website

any idea? [import]uid: 23063 topic_id: 16513 reply_id: 316513[/import]

I believe the page/content is being cached by the OS so when you request the same page, it uses the cached content. Corona doesn’t cache the data but calls the system’s webview API. [import]uid: 7559 topic_id: 16513 reply_id: 61675[/import]

Also: is the device you’re using to test on iOS 5? I read various places that iOS 5 changed the way they handle cached content (within the Cached and tmp directories), so that could also be related. [import]uid: 52430 topic_id: 16513 reply_id: 61677[/import]

so, what I can do to solve this problem?

I need to every time that I open my app, the XML file need to be downloaded to update some informations [import]uid: 23063 topic_id: 16513 reply_id: 61678[/import]

yes, is a iOS 5 [import]uid: 23063 topic_id: 16513 reply_id: 61679[/import]

I would suggest saving to system.DocumentsDirectory instead to see if that helps (I think the iOS5 changes apply mainly to the Cahced and tmp directories).

Also, what mechanism were you using before to determine whether or not to use the cached version of your file vs. re-downloading? Seems like previously, you were intending to re-download every time to see if the server-version had changed. [import]uid: 52430 topic_id: 16513 reply_id: 61687[/import]

I change know to DocumentsDirectory I will check if helps in iOS 5
my code to manege with this download and remove from device is this:

chegaConexao = function()  
 local function networkListener( event )  
 if ( event.isError ) then  
 print( "erro de internet" )  
 else  
 print( "download xml" )  
 native.setActivityIndicator( false )  
 end  
 print ( "RESPONSE: " .. event.response )  
 end  
  
  
  
 local function testeConexao( 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" )  
 semInternet = true  
  
 else  
 network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener, "noticias.xml", system.DocumentsDirectory )  
 semInternet = false  
 end  
 end  
  
 -- Access Google over SSL:  
 network.request( "https://google.com", "GET", testeConexao )  
 native.setActivityIndicator( true )  
  
 \_G.carregarXMLs = false  
 end  
  
 if \_G.carregarXMLs == true then  
 timer.performWithDelay( 500, chegaConexao, 1 )  
 end   
 --  
 --  
-------------------------------------------------------  
-------------------------------------------------------  
-- Here I have put a update button and this is his function  
 atualiza = function()  
 local destDir2 = system.DocumentsDirectory -- where the file is stored  
 local results2, reason2 = os.remove( system.pathForFile( "noticias.xml", destDir2 ) )  
   
 if results2 then  
 print( "file removed" )  
 else  
 print( "file does not exist", reason2 )  
 end  
  
  
 local function networkListener2( event )  
 if ( event.isError ) then  
  
 local function onComplete2( 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" }, onComplete2 )   
 print ( "Network error - download failed" )  
  
 else  
 print( "download xml" )  
 native.setActivityIndicator( false )  
 end  
 print ( "RESPONSE: " .. event.response )  
 end  
  
  
 local function testeConexao( 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" )  
 semInternet = true  
  
 else  
 network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener2, "noticias.xml", system.DocumentsDirectory )  
 semInternet = false  
 end  
 end  
  
 -- Access Google over SSL:  
 network.request( "https://google.com", "GET", testeConexao )  
 native.setActivityIndicator( true )  
 end  
  
-------------------------------------------------------  
-------------------------------------------------------  
-- and in the same .lua down there I have put a fill functions to manege the remove file function  
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  
  
 end  
 end   
  
 Runtime:addEventListener( "system", onSystemEvent )  
  
  
  
 function onSystemEvent2( event )   
 if "applicationResume" == event.type then  
 local function networkListener3( 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", networkListener3, "noticias.xml", system.DocumentsDirectory )  
 native.setActivityIndicator( true )  
 end  
 end   
  
 Runtime:addEventListener( "system", onSystemEvent2 )  
  

So this is it
my code to manege with this XML download
EDIT: never mind guys… seems that after a while the newest version of XML was downloaded if I try to update or re-open my app
don’t know how to explain but… it’s working… for now [import]uid: 23063 topic_id: 16513 reply_id: 61721[/import]

Sounds like the same issue I’m having.
Doesn’t affect Safari, only web views. [import]uid: 10389 topic_id: 16513 reply_id: 69340[/import]

i’m having the same issue… On startup I download the latest database from my server, but if I make changes to the database and upload it to the server then restart the app on the device, it doesn’t download the newest database… last time it took a day before it downloaded it… I make changes to the database every day so my app pretty much has to download the latest database every time.

Anyone who found a solution to this? I managed to fix the issue on the simulator so the simulator now always fetches the latest db. I added “?rnd=”…math.random()" at the end of my URL in the network.download api, but that still didn’t fix it for the device…

iOS 5 here too [import]uid: 14018 topic_id: 16513 reply_id: 77285[/import]

Solved it by not storing network.download() in a local [import]uid: 14018 topic_id: 16513 reply_id: 77287[/import]

Hi Mitaten,
I am having the exact same issue with download() unable to download latest content. May I know what you mean by “not storing network.download() in a local” please? [import]uid: 106266 topic_id: 16513 reply_id: 104364[/import]

same problem now for me… did someone find a solution ?
i do not store anything in a local… just download the file myfile.db and try to use
but it’s always the old version also if i delete before downloading.

In a post i found that is possibile to force a new version in downloading appending a random hash ath the end of my string:
myurl = “http://www.mysite.com/myfile.db”…tostring(math.random())
network.download( myurl, “GET”, networkListener, “myfile.db”, system.DocumentsDirectory )
but it happens that doing like this then the db appers to be not a db anymore or is
seen as encrypted in corona… what can i do ?

[import]uid: 107268 topic_id: 16513 reply_id: 115673[/import]

I had the same problem and found a solution to this. I set the pamas.headers Cache-control to no-cache…

-- Prevent http caching  
local headers = {}  
headers["Cache-control"] = "no-cache"  
local params = {}  
params.headers = headers  
-- Call network download  
network.download( remoteFilePath, "GET", networkListener, params, "myFile.txt", system.TemporaryDirectory)  

[import]uid: 62617 topic_id: 16513 reply_id: 130910[/import]

I had the same problem and found a solution to this. I set the pamas.headers Cache-control to no-cache…

-- Prevent http caching  
local headers = {}  
headers["Cache-control"] = "no-cache"  
local params = {}  
params.headers = headers  
-- Call network download  
network.download( remoteFilePath, "GET", networkListener, params, "myFile.txt", system.TemporaryDirectory)  

[import]uid: 62617 topic_id: 16513 reply_id: 130910[/import]