1

i have database in my app and i want to delete all information from database when user force quit from app. I looked this question Which Event When i close app in iOS? , but when the user click home button, app has force quit in applicationWillTerminate.I don't want to close my app. I just want to catch close event in my app.

Sorry for my bad english. Thanks for advice and interest.

Community
  • 1
  • 1
Kirdok
  • 1,904
  • 2
  • 22
  • 27
  • 1
    In most OSes, forcing an app to quit doesn't even let the app know it's being killed, because it's typically only done when the app has run off the rails and can no longer be trusted to run properly. Not sure about iOS, though. – cHao Jan 05 '14 at 21:36

2 Answers2

2

the OBJC runtime will shut down without any final notification

BUT

you can write a posix signal handler to get the signal. but note that since the runtime is already shutting down it is unsafe to do much work here.

see e.g.: http://chaosinmotion.com/blog/?p=423

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • there are signals that can't be caught by a handler, like `SIGKILL` and `SIGSTOP`. It is fairly likely that `SIGKILL` is the last resort used when force quitting an app. – Ken Thomases Jan 06 '14 at 00:12
1

You can't. The last notification you get that you can be sure of is a didEnterBackground when you get switched to the background. After that, you will likely be killed silently, either from memory pressure or from the user force-quitting you.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • IF iOS is a valid unix system it will call a signal handler that before quitting – Daij-Djan Jan 05 '14 at 22:00
  • my app is downloading information from web service and insert the database.For example; i have 10 informations and i show user these one by one, But user force quit app in middle of the show and opened again. app will download other informations and insert database, in my database i will have 20 information, so i need delete informations when user force quit. How can i do that? or do u have another advice for it? – Kirdok Jan 05 '14 at 22:05
  • 4
    Rather than try to control the shutdown process, which is unpredictable, I would focus on the startup process, and do something like clean out your database to get back to a known good state. – dpassage Jan 05 '14 at 22:07
  • Yeah i got it now, while my app is launching i can clean my database. Thank you so much for advice – Kirdok Jan 05 '14 at 22:14