Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which function is called when iPhone app is terminated?

Tags:

xcode

iphone

ios5

I'm working on a project in Xcode version 4.2.1 and in iOS 5.0. I'm wondering which function will be called when you completely terminate an application, which means even the time when an users force the app running on background to be terminated from home screen. I was assuming that

(void)applicationWillTerminate:(UIApplication *)application

would be called, but it turned out it was not called even after terminating the app on background. What I basically want to do is to call a method that I created just before the app is completely terminated, so need to know which function is called at the end of the app.

Thank you.

like image 893
Max Avatar asked Apr 17 '12 23:04

Max


1 Answers

"applicationWillTerminate" method will be called only when application is not in suspended state while being terminated.

To understand this, considering currently your application is in foreground active state, go through following two cases:

Case 1: When you single tap Home button, app directly goes to suspended state by calling methods - (1) applicationWillResignActive and then (2) applicationDidEnterBackground.

Now when you try to quit/terminate app, by double tapping home button and then swiping up the current app screen from recent app screens, app is in suspended state. So, "applicationWillTerminate" method will not be called.

Case 2: When you double tap Home button, app goes to inactive state by calling method - (1) applicationWillResignActive.

Now when you try to quit/terminate app, by swiping up the current app screen from recent app screens, app is in inactive state (not in suspended state) while being terminated. So, "applicationWillTerminate" method will be called.

Look what Apple say: enter image description here

For more info on this look - Apple's Official Documentation on applicationWillTerminate(_:)

like image 105
Nitesh Borad Avatar answered Dec 28 '22 23:12

Nitesh Borad