5

In my iphone app, I want to provide some sort of app termination handler that will do some final work (delete some sensitive data) before the application terminates.

I want to handle as much of the termination situations as possible:
1) User terminates the app
2) The device runs out of battery
3) The system terminates the app due to some reason (e.g. out of memory or app freeze)
4) Application crashes (EXC_BAD_ACCESS or SIGSEGV)

Any other exceptional situation ?
What is the best way to achieve this (e.g. is applicationWillTerminate method called in situation 2) ?
Is it possible to do the cleanup in a signal handler (includes iPhone Security framework calls) ?

regards

pmilosev
  • 932
  • 8
  • 20
  • Your sensitive data is written to persistent storage? Is there a way you can just create it in-memory? If using SQLite, it supports in memory databases. – NG. May 17 '10 at 12:51
  • No, my data is stored into keychain :) However I am working on an e-banking application and my client wants me to manually encrypt all the data (including keys) before storing them into keychain. Since this is not supported by the SDK I have to do some sort of a hack regarding the keys and data signing (see my previouse post here: http://stackoverflow.com/questions/2826090/iphone-data-signing-using-nsdata-of-the-private-key). So I keep decrypted version of the keys into keychain during the app lifetime in order to be able to do signing, and then on app termination I would like to delete it. – pmilosev May 17 '10 at 18:03

1 Answers1

1

This timely post will help you with 4) to start with.

You know when your app is going to terminate from your app delegate and you can listen for notifcations to battery changes, see UIDevice.

petert
  • 6,672
  • 3
  • 38
  • 46