[iOS] Events in the Appdelegate method of iOS trigger calls and close iOS apps

Source: Internet
Author: User

An event-triggered call in the iOS Appdelegate method

Reference: http://blog.sina.com.cn/s/blog_a573f7990101bphp.html

//when an application is about to go into an inactive state, during which time the application does not accept messages or events, such as incoming calls- (void) Applicationwillresignactive: (UIApplication *) Application {NSLog (@"the application is going to be inactive and will be entering the background"); }    //The application is running in the background- (void) Applicationdidenterbackground: (UIApplication *) Application {NSLog (@"if the application supports background running, the application is already running in the background"); If you need to exit the background, add this here: Exit (0);} //The application is about to enter the active state execution- (void) Applicationwillenterforeground: (UIApplication *) Application {NSLog (@"the application will enter the active state and will be running in the foreground"); }    //The application has entered the active state- (void) Applicationdidbecomeactive: (UIApplication *) Application {NSLog (@"the application has entered the foreground and is active"); }    //applications are going to exit, usually used to save the bookshelf to drink some pre-launch cleanup work,- (void) Applicationwillterminate: (UIApplication *) Application {NSLog (@"applications are going to exit, usually used to save the bookshelf to drink some pre-launch cleanup work"); }    //when the device allocates too much memory to the application, the operating system terminates the application and executes the method before terminating .//memory cleanup can usually be done here to prevent the program from being terminated-(void) Applicationdidreceivememorywarning: (UIApplication *) Application {NSLog (@"system memory is low and cleanup is required"); }    //executes when the system time has changed-(void) Applicationsignificanttimechange: (UIApplication *) Application {NSLog (@"executes when the system time has changed"); }    //executes when the program is loaded-(void) Applicationdidfinishlaunching: (UIApplication *) Application {NSLog (@"executes when the program is loaded"); } 

Press Home key is processing Applicationdidenterbackground, after the program processing Applicationdidenterbackground, the system will let the program have 5 seconds to retain data, for the general data storage, 5 seconds enough.
Applicationwillterminate Press the home key cannot be called

Get the Uiviewcontroller method in Appdelegate:

Uiviewcontroller *VC = (Uiviewcontroller *) Self.window.rootViewController

Turn off iOS

Reference: http://blog.163.com/wzi_xiang/blog/static/65982961201302210854891/

A line of code

Exit (0);

[iOS] Events in the Appdelegate method of iOS trigger calls and close iOS apps

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.