Basically what I need to do here is to download a XML file from a web server by registering my device (iPAD) which I’ve already done.
So, I thought of doing it like this :
- I request the server to get me the file , ‘….getfile.php?key’
- If the file is ready for export we get a acknowledgement saying ‘OK’
- Sending a request ‘..downloadfile.php’
- get a response which includes file size and other info.
- send a request and download file- ‘DownloadFile.php’.
- send a response download complete and fetch complete.
How do I do this?
When interacting with web servers, you should research
NSURLConnectionwhich is discussed in the URL Loading System Programming Guide. If you want to simplify your coding effort, you can use a framework such as RestKit, AFNetworking, or something like that.In my mind, you seem to describe two types of interactions with the server. First, you have a request for XML response, and the parsing of that response. That is relatively easy. You just create a
NSXMLParserusinginitWithContentsOfURL. The most prevalent demonstrations of iOS apps parsing XML would be RSS readers, and if you google “iOS RSS tutorial”, you’ll get lots of wonderful hits. Also see my sample News Parser as an example. You can also google “NSXMLParser tutorial”, though the hits seem less compelling.Second, you have a request to download a file. If the files are very small (e.g. measured in kb, not mb or gb), this is very easy. You just use
dataWithContentsOfURLto load it into aNSData, and then you do awriteToFileto save it to a file. Just those two lines of code.If the files are larger, though, it gets more complicated, because you probably don’t want to hold the files in memory, and you probably want some notification of the download progress. I’m not sure if the above third party libraries do this or not. I have an
NSURLConnectiondownload example or you can just google “NSURLConnection download tutorial”.