I need to send data to the server. If no internet connection is present, I want to simply store this textual data into a “file” on the iOS file system.
Periodically we will check the internet connection, if we have it we need to check if there are any files in the file system and how many, then I need to extract the data from the file and ship it to the server as normal. Then delete the file.
So what I don’t know how to do:
1) Save text to a file in the local device file system
2) Check that file system if there are any files
3) Iterate through the files and extract the data from each one
4) Delete the file after the data hits the server
Thanks
The only place where you can save a file is in the application’s documents directory. There is a separate one for each application.
1) You save files using
NSFileManager.2) You also use
NSFileManagerto check for files in the documents directory,3) including iteration
4) and deletion.
You get the documents directory like this:
You save a file like this:
You get an array of directory contents for iteration like this:
Delete a file: