network.download on ios

Hi,

I have a json file on my web that I use for ads in my app. 

Json file is downloaded with the code below:

 function networkListener( event ) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began" ) elseif ( event.phase == "ended" ) then print( "Done" ) json = require("json") src = "toddler.json" path = system.pathForFile(src, system.DocumentsDirectory) saveData = io.open(path, "r") Data = saveData:read("\*a") t = json.decode(Data) io.close(saveData) end end local params = {headers = { ["Accept-Encoding"] = "" }} params.progress = true network.download( "http://my-domain.com/app/toddler.json", "GET", networkListener, params, "toddler.json", system.DocumentsDirectory )

Now I have a problem with download on iOS. On android everything works perfectly: json file is downloaded, ads are showing and working,

even when I update json file on the web, the updated version is downloaded (old one in the system.DocumentsDirectory is deleted before that) and working as it should - but only on android.

On iOS it downloads the json file but shows old content of the file, which is totally strange because old file is deleted :confused:

Any ideas what I’m doing wrong?

Mladen

I’ve had this before, somehow it retrieves an old cached version (not sure it mattered which OS I used though).  

Try adding a random parameter to the end of the url, that usually forces it to treat the request as a completely new request:

local rand = math.random(1, 10000) network.download( "http://my-domain.com/app/toddler.json?"..rand, "GET", networkListener, params, "toddler.json", system.DocumentsDirectory )

Thank you Alan,

it works now :slight_smile:

Glad to hear that worked. For the record, I add a random parameter like this to all my network.downloads just to be sure that nothing gets cached, so it may be wise for you to do the same.

I’ve had this before, somehow it retrieves an old cached version (not sure it mattered which OS I used though).  

Try adding a random parameter to the end of the url, that usually forces it to treat the request as a completely new request:

local rand = math.random(1, 10000) network.download( "http://my-domain.com/app/toddler.json?"..rand, "GET", networkListener, params, "toddler.json", system.DocumentsDirectory )

Thank you Alan,

it works now :slight_smile:

Glad to hear that worked. For the record, I add a random parameter like this to all my network.downloads just to be sure that nothing gets cached, so it may be wise for you to do the same.