Is there any callback methods to be called When the user closes the app from the Task Manager? Because i have to maintain the status i.e Online or Offline while killing the app from the task manger user should become offline.
-
i think applicationWillTerminate method – Jigar Mar 20 '17 at 05:10
-
1Possible duplicate of [iOS how to detect when app was removed from process](http://stackoverflow.com/questions/17840893/ios-how-to-detect-when-app-was-removed-from-process) – Mar 20 '17 at 05:13
-
As C does not support _methods_, we can exclude this language. Please remove the other unrelated languages yourself. – too honest for this site Mar 20 '17 at 05:21
-
You're going around this the wrong way. Use a websocket to the server, which will give you a connection you can detect the on/offline nature of. – ceejayoz Mar 20 '17 at 05:34
3 Answers
No, there is no such method or function or method to handle this scenario.
func applicationWillTerminate(application: UIApplication){}
// This method will be called when system kills your app after suspending it for whatever reason.
There is no method to detect killing application by multitasking and swipe the app Up to kill(from task manager).
Though you can handle this scenario in
func applicationDidEnterBackground(application: UIApplication) {}

- 2,988
- 1
- 21
- 43
-
This is what i have done, when ever app will be sent to background i made user offline. same way WhatsApp does* i think – Devang Tandel Mar 20 '17 at 05:45
Previous answers contain needed information. The application has delegate @protocol
methods that handle application appearance, focus, entereing background state or termination.
If your question is how to handle this events in the context of data transfer and sending some status outside - register NSNotification
observer and postNotification
from the delegate protocol handler. Notifications are being sent before any other actions and allow the app to inform remote resource that it will be closed or loses focus.

- 1,613
- 16
- 17
In Ruby
at_exit do
# Do whatever you want before exit
end
Or if you want to do something before a specific signal that causes your program to exit, then
trap :INT do
# Will be triggered when `SIGINT` is trapped
end
You can replace :INT
with other signals you want to trap.

- 8,720
- 1
- 22
- 36