views:

282

answers:

3

I want to save my data into a text file when the user presses the home button. How to do so?

+2  A: 

Implement applicationWillTerminate: in your application delegate. Save your application's data in that method.

Toon Van Acker
+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
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
+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