- (void)applicationDidEnterBackground:(UIApplication *)application {
//...function_a call
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
//...function_b call
}
- (void)applicationWillTerminate:(UIApplication *)application {
//...function_c call
}
I'm tracking my app with AppDelegates methods. Its working fine, if app just go / up from background to foreground. But when I try to remove my app from the running applications then, it will first call - (void)applicationDidEnterBackground:(UIApplication *)application
and then, will call - (void)applicationWillTerminate:(UIApplication *)application
. How do I know in - (void)applicationDidEnterBackground:(UIApplication *)application
that app is being terminating. By mean, I don't want function_a
call twice instead it should only call when app goes into background.
Update:
Setting even following observer doesn't help.
UIApplicationDidEnterBackgroundNotification
UIApplicationWillEnterForegroundNotification
UIApplicationWillTerminateNotification
- (void)applicationWillTerminate:(UIApplication *)application
:
This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers. Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.
For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.
So this is the to go delegate method to know when the app will be terminated, either by the user or by the system, while - (void)applicationWillTerminate:(UIApplication *)application
runs whenever the app goes to the background, it doesn't mean it was exitted, unless your exit means not visible