2

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

3 Answers 3

6

Implement applicationWillTerminate: in your app delegate. Do whatever you need to do to turn your data into text, and save it.

1
  • 3
    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
    Jul 20, 2009 at 2:24
2

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy