iOS - detect when application exits

核能气质少年 提交于 2020-01-30 05:17:05

问题


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!


回答1:


- (void)applicationDidEnterBackground:(UIApplication *)application

and

- (void)applicationDidBecomeActive:(UIApplication *)application

In your AppDelegate.m

- (void)applicationWillTerminate:(UIApplication *)application



回答2:


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



来源:https://stackoverflow.com/questions/9447690/ios-detect-when-application-exits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!