appdelegate.m//ui1_ application life cycle////Created by zhangxueming on 15/6/29.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "AppDelegate.h"//Development tools://1.xcode: Edit Engineering Code, modify Project//2.ios Simulator: Simulator, simulate iphone on Mac computer Device Operating Environment//3.instrument: Memory Analysis Tool//4.iphone Development Kit (SDK): Apple's official development environment//5.interface Bulider (Xib): Provides UI interface with user interface//code creation//sandbox ( Sandbox)//For security reasons, each application has its own separate file directory structure//application cannot share data//application state//not running not run program does not start//inactive inactive program runs in foreground, but no event is received 。 In the absence of event handling, the program usually stays in this state//active the activation program runs in the foreground and receives the event. This is also a normal mode of the foreground//backgroud daemon in the background and can execute code, most of the program into this state will stay in this state for a while. The time will then go into the suspended state (Suspended). Some programs after a special request can be long-term in the Backgroud state//suspended suspend program in the background can not execute code. The system automatically turns the program into this state and does not give notice. When suspended, the program is still in memory, when the system memory is low, the system will remove the suspended program, to provide more memory for the foreground program. @interface appdelegate () @end @implementation appdelegate//application startup Call-(BOOL) Application: (UIApplication *) application Didfinishlaunchingwithoptions: (nsdictionary *) launchoptions {//Override point for customization after application Lau Nch. Write code here Self.window.backgroundColor = [Uicolor Yellowcolor]; Self.window.rootViewController = nil; Gets the current Application object uiapplication *app = [UIApplication sharedapplication]; Gets the proxy for the current application appdelegate *delegateapp = app.delegate; NSLog (@ "app =%@ delegate =%@", app, Delegateapp); return YES;} Going into background mode (lock screen)-(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application is ABO UT to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 1. External interrupt event entry, such as: telephone or short message Access//2. Switch backstage from the foreground, and exit the application//3. Pause the task in progress, pause the timer, lower the OpenGL frame rate, pause the running game NSLog (@ "%@ has been called ", NSstringfromselector (_cmd));} Call this method after entering the background-(void) Applicationdidenterbackground: (uiapplication *) application {//Use this method to release shared R esources, save user data, invalidate timers, and store enough application state information to restore your application to It is terminated later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits. Release shared resources, save user data, void timers, store sufficient application state information to restore applications from the background to the front desk//If the application supports background mode, this method replaces Applicationwillterminate:nslog (@ "%@ has been called!!! ", Nsstringfromselector (_cmd));} Called when the application is going to enter the foreground-(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the Transitio n from the background to the inactive state; Here's can undo many of the changes made on entering the background. Start timer, increase OpenGL frame rate start Game NSLog (@ "%@ has been called!!!", Nsstringfromselector (_cmd));} After entering the foreground mode-(void) Applicationdidbecomeactive:(UIApplication *) application {//Restart any tasks this were paused (or not yet started) while the application is ina Ctive. If the application is previously in the background, optionally refresh the user interface. Restart the paused task, refresh the UI NSLog (@ "%@ has been called!!!", Nsstringfromselector (_cmd));} Memory emergency is called-(void) applicationdidreceivememorywarning: (uiapplication *) application{//Free memory NSLog (@ "%@ has been called! !! ", Nsstringfromselector (_cmd)); Application stopped being called (application does not support background mode)-(void) Applicationwillterminate: (uiapplication *) application {//called when the application is on to terminate. Save data if appropriate. See also Applicationdidenterbackground:. Saves changes in the application ' s managed object context before the application terminates. [Self savecontext]; NSLog (@ "%@ has been called!!!", Nsstringfromselector (_cmd));} #pragma mark-core Data stack@synthesize managedobjectcontext = _managedobjectcontext; @synthesize Managedobjectmodel = _ ManagedobjectmodEl; @synthesize persistentstorecoordinator = _persistentstorecoordinator;-(Nsurl *) applicationdocumentsdirectory {// The directory the application uses to store the Core Data store file. This code uses a directory named " -000phone.com.ui1___________" in the application ' s documents directory. return [[[Nsfilemanager Defaultmanager] urlsfordirectory:nsdocumentdirectory Indomains:nsuserdomainmask] LastObject ];} -(Nsmanagedobjectmodel *) Managedobjectmodel {//The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. if (_managedobjectmodel! = nil) {return _managedobjectmodel; } nsurl *modelurl = [[NSBundle mainbundle] urlforresource:@ "ui1___________" withextension:@ "MOMD"]; _managedobjectmodel = [[Nsmanagedobjectmodel alloc] initwithcontentsofurl:modelurl]; return _managedobjectmodel;} -(Nspersistentstorecoordinator *) Persistentstorecoordinator {//The persistent Store Coordinator For the application. This implementation creates and return a coordinator, has added the store for the application to it. if (_persistentstorecoordinator! = nil) {return _persistentstorecoordinator; }//Create the Coordinator and store _persistentstorecoordinator = [[Nspersistentstorecoordinator alloc] In Itwithmanagedobjectmodel:[self Managedobjectmodel]]; Nsurl *storeurl = [[Self applicationdocumentsdirectory] urlbyappendingpathcomponent:@ "Ui1___________.sqlite"]; Nserror *error = nil; NSString *failurereason = @ "There is an error creating or loading the application ' s saved data."; if (![ _persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil URL:storeURL options: Nil Error:&error]) {//Report any error we got. Nsmutabledictionary *dict = [Nsmutabledictionary dictionary]; Dict[nslocalizeddescriptionkey] = @ "Failed to initialize the application ' s saved data"; Dict[nslocalizedfAilurereasonerrorkey] = Failurereason; Dict[nsunderlyingerrorkey] = error; Error = [Nserror errorwithdomain:@ "Your_error_domain" code:9999 userinfo:dict]; Replace this with code to handle the error appropriately. Abort () causes the application to generate a crash log and terminate. You should don't use the This function in a shipping application, although it could be useful during. NSLog (@ "unresolved error%@,%@", error, [error userInfo]); Abort (); } return _persistentstorecoordinator;} -(Nsmanagedobjectcontext *) Managedobjectcontext {//Returns the managed object context for the application (which) Already bound to the persistent store coordinator for the application.) if (_managedobjectcontext! = nil) {return _managedobjectcontext; } nspersistentstorecoordinator *coordinator = [self persistentstorecoordinator]; if (!coordinator) {return nil; } _managedobjectcontext = [[nsmanagedObjectContext alloc] init]; [_managedobjectcontext Setpersistentstorecoordinator:coordinator]; return _managedobjectcontext;} #pragma mark-core Data saving support-(void) Savecontext {nsmanagedobjectcontext *managedobjectcontext = Self.manage Dobjectcontext; if (managedobjectcontext! = nil) {Nserror *error = nil; if ([Managedobjectcontext haschanges] &&![ Managedobjectcontext Save:&error]) {//Replace This implementation with code to handle the error Appropria Tely. Abort () causes the application to generate a crash log and terminate. You should don't use the This function in a shipping application, although it could be useful during. NSLog (@ "unresolved error%@,%@", error, [error userInfo]); Abort (); }}} @end
The life cycle of a program ui1_ application