I am writing an application that connects and constantly communicates with our server over the course of a day.
During this day a user might or might not loose their connection, being out of range etc I was wondering what is the best way to handle these instances, in regards to the way my code acts and also they way I inform the user.
*NOTE: I am assuming that you want to perform network operations across HTTP
Reads
For data that is read, it depends on what your assumptions are around how fast it changes.
For changeable data (data that is anticipated to change say a few times per day), use SDURLCache. SDURLCache provides the HTTP local cache. If you hook it up with AFNetworking, then it will also respect standard HTTP caching behaviours (expire headers, etags etc).
For ‘static’ data, you can bundle the data locally with the application, and periodically check for updates via HTTP.
In either case, you should try (if possible) to package some data with the app so that the day the App is installed, it may not need network connectivity to run at all.
Writes
For writes, the best way to handle this is to queue all your writes and post them at an appropriate time. Implementing a queue is relatively simple, and much will depend on how to store things locally. One way would be to set flags in the SQLite db table to indicate data elements that need posting to the server side. Another could be to construct documents and write them to disk, having a separate dispatch thread to post them off to the server side when there is connectivity.