//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"); }
After introducing the method in Appdelegate, go back to the place I want to say
If these methods are triggered in a viewcontroller (such as pressing the home keyboard, the program will enter the background, triggering
Applicationwillresignactive,
Applicationdidenterbackground
method), it is not possible to write logic processing back to appdelegate, so we can use the observer pattern to deal with this problem:
-(void) viewwillappear: (BOOL) animated { [Super viewwillappear:animated]; [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (AA) name: Uiapplicationdidfinishlaunchingnotification object: nil];}
The name you receive here can be a lot:
Uiapplicationdidfinishlaunchingnotification
Uiapplicationdidenterbackgroundnotification
The corresponding methods in Appdelegate are
The method of delegating protocol in Appdelegate and its triggering method using observer pattern