Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - detect when application exits

Tags:

ios

exit

quit

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!

like image 817
Albert Renshaw Avatar asked Feb 25 '12 20:02

Albert Renshaw


People also ask

Will iOS terminate the app running in background after a specific time?

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.

How do I know if an app is running in the background on iOS?

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.

What is app life cycle in Swift?

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.


2 Answers

- (void)applicationDidEnterBackground:(UIApplication *)application

and

- (void)applicationDidBecomeActive:(UIApplication *)application

In your AppDelegate.m

- (void)applicationWillTerminate:(UIApplication *)application
like image 173
0xDE4E15B Avatar answered Oct 05 '22 11:10

0xDE4E15B


There's a notification UIApplicationDidGoToBackground that fires when the home button is pressed. A similar notification tells you about going back to foreground.

like image 29
Nikolai Ruhe Avatar answered Oct 05 '22 11:10

Nikolai Ruhe