How to monitor when apps are turned off-IOS

Source: Internet
Author: User

In the appdelegate.

applicationWillTerminate

is when the processing application will terminate

By the way, we're going to be doing this in this place when our App is closed.

但是,我发现 App 关闭的时候,并不会走到这里来。

Then I looked at the comments for the system:当应用程序即将终止时调用。如果适当的保存数据。可看 appropriate. See also applicationDidEnterBackground:. 这个方法

It seems to have nothing to do with the problem I'm having! I just want to call when the APP is closed

// 应用程序将终止- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.    NSLog(@"applicationWillTerminate");}

好了,答案来了。

We go to Applicationdidenterbackground to execute a method with the following code:

// 我们到 applicationDidEnterBackground 执行下 beginBackgroundTaskWithExpirationHandler- (void)applicationDidEnterBackground:(UIApplication *)application {    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.    [[UIApplication sharedApplication]beginBackgroundTaskWithExpirationHandler:^(){    }];    NSLog(@"applicationDidEnterBackground");}// 这时候你就会发现 applicationWillTerminate 这货被调用了,有没有人过来解释下。。- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.    NSLog(@"applicationWillTerminate");}

How to monitor when apps are turned off-IOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.