问题
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