I want to save my data into a text file when the user presses the home button. How to do so?
3 Answers
Implement applicationWillTerminate:
in your app delegate. Do whatever you need to do to turn your data into text, and save it.
-
3also, 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! Jul 20, 2009 at 2:24
Implement applicationWillTerminate: in your application delegate. Save your application's data in that method.
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.