开发者

How can I know whether app is terminated by user?

How can I know whether app is terminated by user?

(Double-clicking Home button and press red minus '-' button)

I need sample or pseud开发者_开发问答o code...


Sometimes you do get the UIApplicationWillTerminateNotification (you can also implement the applicationWillTerminate: method in your app delegate), but it's not guaranteed that you do get any notification at all in this case. So don't rely on it.

You won't receive the notification if your app is "suspended", that is it is in background but not running. In the suspended case you simply get killed with the non-catchable SIGKILL. Same for when you get killed due to out-of-memory.

From the documentation for applicationWillTerminate: (emphasis mine):

For applications 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 application. For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.


When user kills the app:

- (void)applicationWillTerminate:(UIApplication *)application{

}

Application will enter inactive state:

 - (void)applicationWillResignActive:(UIApplication *)application
 {
  NSLog(@"Application Did Resign Active");
 }

User pushes Home button:

 - (void)applicationDidEnterBackground:(UIApplication *)application
{
  NSLog(@"Application Did Enter Background");
}


Try this:

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

You should implement the method above in your class that implements UIApplicationDelegate

Some more notes: that method won't be called if you are stopping your app via Xcode (stop debug button). So be patient when testing.


Also there is this:

- (void)applicationDidEnterBackground:(UIApplication *)application {

}

Could be helpful if you want to know did it enter background ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜