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