My IOS App periodically collects data that is time and location stamped (from GPS). That data is sent to a server if the app is online at the time the data is collected. BUT, if a data connection is not available I want the data cached to the iPhone/iPad until a data connection is obtained. When the connection is restored the data is uploaded and the cache is cleared. The data is in the form of an array of strings of SQL. Typically the array might contain a dozen or few dozen strings--nothing too large. The data should be persistent until it is cleared even if the app or device is shut down. Suggestions?
Asked
Active
Viewed 533 times
2 Answers
0
I think the best way is to work with CoreData or you store the values in a local file.

Ben
- 3,455
- 3
- 26
- 31
-
I thought about both. Which is best? Core Data seems like a lot of effort for such a simple task. A local file is definitely a possibility, but is it best? – SchroedingersCat Jun 01 '14 at 19:13
-
You're right, CoreData would be too much effort for this. I would appreciate to store the data in a local file, but I am not sure if this is the best solution. But I think it should work perfectly. NSUserDefaults would be another option, but I think its a little bit more effort.. – Ben Jun 01 '14 at 20:37
0
Have you thought about using NSUserDefaults for small amounts of data it is a value, key map solution and very simple. For large amounts of data something like JSON is good. Simply make the JSON when the data is created and then when connection in the app is detected parse the JSON and send it to the server.

Martin O'Shea
- 432
- 5
- 15
-
I like the idea of using NSUser defaults if that is the best way to do it. I am storing the finished query as it tries to send immediately--otherwise it stores it. Not much work to do when the connection comes back. – SchroedingersCat Jun 01 '14 at 19:15
-
There are many ways of solving this problem the above are just a few. You make your data into an array and store it using NSUserDefaults. I think this post should help you if you choice this path http://stackoverflow.com/questions/4690290/how-to-store-nsmutablearray-in-nsuserdefaults – Martin O'Shea Jun 02 '14 at 11:43
-
I chose this as the answer because this is what I chose to do. I get the sense that there is no clearly better way to do this. I used NSUserDefaults because I was already using the class for more usual "defaults" storage. – SchroedingersCat Jun 03 '14 at 12:46