How can I detect when a user exits the application? (hitting the home button) And how can I detect when the relaunch it? (clicking the icon)
*I'm not talking about users manually quitting the app by holding the home button and then making the icons wiggle and deleting the app instance from the sub-dock. i'm talking about just temporarily exiting the app buy clicking the home button.. maybe sending a text or whatnot then coming back to the app.
Thanks!
At the same time, didReceiveMemoryWarning is invoked for the app. At this point, so that your app continues to run properly, the OS begins terminating apps in the background to free some memory. Once all background apps are terminated, if your app still needs more memory, the OS terminates your app.
To detect if an iOS application is in background or foreground we can simply use the UIApplication just like we can use it to detect many other things like battery state, status etc. The shared. application state is an enum of type State, which consists of the following as per apple documentation.
An iOS application runs into several states, which are called the state of the Application life cycle. Every iOS developer must be aware of the app life cycle, which helps to understand the application's behavior. Every iOS application passes through the following states as it runs.
- (void)applicationDidEnterBackground:(UIApplication *)application
and
- (void)applicationDidBecomeActive:(UIApplication *)application
In your AppDelegate.m
- (void)applicationWillTerminate:(UIApplication *)application
There's a notification UIApplicationDidGoToBackground
that fires when the home button is pressed. A similar notification tells you about going back to foreground.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With