Application suspension, recovery, and termination-iOS development

Source: Internet
Author: User
Statement

You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you.
ArticleSource: http://blog.csdn.net/iukey

I. Pending

When a phone call comes in or locks the screen, your application will be suspended. At this time, the uiapplicationdelegate delegate will receive a notification and call the applicationwillresignactive method. You can rewrite this method to do the work before suspension, for example, disable the network and save data.

 
-(Void) applicationwillresignactive :( uiapplication *) Application {/* add your own pending preparationsCode*/}

When yourProgramIt will not run in the background after being suspended.
Ii. Restoration
When the program is restored, another method named applicationdidbecomeactive is called. You can restore your application by using the data saved before suspension:

-(Void) applicationdidbecomeactive :( uiapplication *) Application {/* add your recovery Code */}

Note: When an application is started, the applicationdidfinishlaunching method will also be called after the applicationdidbecomeactive method is called. Therefore, make sure that your code can distinguish recovery and startup to avoid logical bugs.
Iii. Termination
When you press the button or shut down, the program will be terminated. The applicationwillterminate method is called when a program is about to terminate normally. However, if the long master button is forced to exit, this method is not called. This method should be used to execute the remaining cleanup work. For example, all connections can be closed normally and any other necessary work should be executed before the program exits:

 
-(Void) applicationwillterminate :( uiapplication *) Application {/* Add the cleanup code and other work code before exiting here */}

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.