I want to save my data into a text file when the user presses the home button. How to do so?
views:
282answers:
3
+2
A:
Implement applicationWillTerminate: in your application delegate. Save your application's data in that method.
Toon Van Acker
2009-07-20 02:07:33
+6
A:
Implement applicationWillTerminate:
in your app delegate. Do whatever you need to do to turn your data into text, and save it.
BJ Homer
2009-07-20 02:08:36
also, make sure you don't spawn any threads to do the heavy lifting of your save process. Once applicationWillTerminate is called, you can't create new threads or they terminate immediately. I had a threaded save function, and it took forever to find the problem!
Ben Gotow
2009-07-20 02:24:11
+1
A:
Note that applicationWillTerminate is only a kindness to your application, and if it takes too long your application will be closed down anyway.
It's way better, if possible, to update the file in question periodically so a failed save at the end will not matter.
Kendall Helmstetter Gelner
2009-07-20 03:38:14