Okay, lets try to simplify this as much as possible without writing a whole multi-issue blog post on the topic.
First “Asynchronous” simply means in this case, the network activity happens in the background and your app will be notified when the download is done an opposed to your app stopping to wait on the download to finish (synchronous)
Basically you fire off the request with a function to do something when the download is finished (a “CallBack” function, i.e. the network function “calls back” to your programming saying I’m done. You then have a function that will read the file in and display it however you want.
The method in the post above is a synchronous call or a blocking call in that your app will stop and wait on the download. This isn’t bad for small files, but can hurt the user experience for larger files. I should also point out that if you’re planning on putting this in iTunes for iOS people to download, you probably should change the “system.DocumentsDirectory” to “system.CachesDirectory” since Apple doesn’t want reproducible files from the network in system.DocumentDirectory.
Corona SDK offers two asynchronous tools to download content:
network.download()
http://developer.anscamobile.com/reference/index/networkdownload
and
network.request()
http://developer.anscamobile.com/reference/index/networkrequest
network.download() and network.request() both contact a remote web server and download the resulting content. If you are fetching a document that you need to save to your storage or a big file, you want to use network.download(). network.request() is best for getting small bits of data that you don’t need to store. It sounds like your app could use either with the size of the data being the deciding factor.
To use either of them you need a URL on your webserver that’s going to deliver the data. This could be a text file, XML, JSON, or any other format that your server can deliver.
If you use network.request, the results will be in the event table passed to the function in the response variable (event.response) and then you can deal with the data as necessary.
If you use network.download, the results will be saved to a file, then you have to open the file and read it in.
Regardless you will need to parse the data into something you can use. JSON is a very easy way code wise to manage since it gives you a table to work with. JSON can be scary when you have to try and learn the format, but if you have something that can produce the JSON for you, such as a web-form with PHP where your customer can type in the data and hit save, then in the PHP script, those variables are put into a PHP array, then run PHP’s json_encode() function and deliver the string it outputs as the result of your network.request, then you can do a mytable = json.decode(event.response) to get the data automatically into Corona so you can use it. [import]uid: 19626 topic_id: 23166 reply_id: 92764[/import]