Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ApplicationWillTerminate in iOS 4.0

The applicationWillTerminate delegate method is not getting called in iOS 4.0 When I hit the Home button I am seeing the applicationWillResignActive and applicationDidEnterBackground delegate methods getting called.

 - (void)applicationWillResignActive:(UIApplication *)application {   NSLog(@"Application Did Resign Active"); }  - (void)applicationDidEnterBackground:(UIApplication *)application {   NSLog(@"Application Did Enter Background"); } 

And when I double Tap the Home button and again launch the Application the i find the applicationWillEnterForeground and applicationDidBecomeActive delegate methods are getting called.

 - (void)applicationWillEnterForeground:(UIApplication *)application {   NSLog(@"Application Will Enter Foreground"); }    - (void)applicationDidBecomeActive:(UIApplication *)application {   NSLog(@"Application Did Become Active"); } 

But I want to know when the applicationWillTerminate delegate method will be called , where I do some DB/file backup routines.

- (void)applicationWillTerminate:(UIApplication *)application{  } 

I even tried to hit the minus sign and deleted the App running in the Background , but still it did not call any delegate method.

Any Ideas ???

like image 759
Biranchi Avatar asked Jun 29 '10 09:06

Biranchi


People also ask

What is iOS Appgroup?

App groups allow multiple apps produced by a single development team to access shared containers and communicate using interprocess communication (IPC). Apps may belong to one or more app groups. For iOS, format the identifier as follows: group.<group name>

What is the use of SceneDelegate in Xcode 11?

The AppDelegate will be responsible for the application lifecycle and setup. The SceneDelegate will be responsible for what is shown on the screen (Windows or Scenes) handle and manage the way your app is shown.

When applicationWillEnterForeground is called?

applicationWillEnterForeground: is called after application: didFinishLaunchingWithOptions : or if your app becomes active again after receiving a phone call or other system interruption. applicationDidBecomeActive: is called after applicationWillEnterForeground: to finish up the transition to the foreground.


2 Answers

From the iPhone Application Programming Guide:

Even if you develop your application using iPhone SDK 4 and later, you must still be prepared for your application to be terminated. If memory becomes constrained, the system might remove applications from memory in order to make more room. If your application is currently suspended, the system removes your application from memory without any notice. However, if your application is currently running in the background, the system does call the applicationWillTerminate: method of the application delegate. Your application cannot request additional background execution time from this method.

So yes, applicationWillTerminate: will generally not be called very often in iOS 4. If you have to save data, you should do so in both applicationWillTerminate: and applicationDidEnterBackground:.

like image 162
Ole Begemann Avatar answered Sep 27 '22 22:09

Ole Begemann


The WWDC 2010 Session Adopting Multitasking on iPhone OS (Part 2) explains the application state transitions extremely well.

like image 41
falconcreek Avatar answered Sep 27 '22 21:09

falconcreek