-
- iOS program startup process
- Full START process
- Uiapplicationmain method
- UIApplication
- Appdelegate Proxy life cycle callbacks
- UIWindow
- Uiviewcontroller Controller
- Load of Controller view
- Common Files for iOS engineering
- Xxx-infoplist file
- Infopliststrings
- Xxx-prefixpch
- Defaultpng
- Iconpng
iOS program startup process
1. Complete start-up process
- Click the program icon
- Executes the main function
- Execute the Uiapplicationmain function
- Create a UIApplication object, UIApplication delegate object
- Turn on the event loop monitoring system
- method to invoke the delegate object after the program has finished loading
application:didFinishLaunchingWithOptions:
- Creating a Window Object
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- To create a Controller object
self.viewController = [[MJViewController alloc] initWithNibName:@"MJViewController" bundle:nil];
- Setting the root controller of a window
self.window.rootViewController = self.viewController;
- Make a window The main window, and visible
[self.window makeKeyAndVisible];
2. Uiapplicationmain Method
?? The Uiapplicationmain method is executed in the main function of MAIN.M, which is the entry point of the iOS program.
int UIApplicationMain(int*argv*principalClassName*delegateClassName)
argc、argv
: ISO C Standard Main function parameters, directly passed to the Uiapplicationmain for related processing;
principalClassName
: Specifies the application class, which must be a uiapplication (or subclass).
delegateClassName
: Specifies the proxy class for the application class, which must comply with the Uiapplicationdelegate protocol;
This function creates an object based on Principalclassname UIApplication
, creates an object from Delegateclassname delegate
, and assigns the delegate object to the delegate property in the UIApplication object The UIApplication object sends a different message to the delegate object in turn, and then builds the application's main Runloop (event loop) to handle the event (the application of the delegate object is called first: Didfinishlaunchingwithoptions:), the function returns when the program exits normally. If the process is forced to be killed by the system, the function is usually terminated before it can return to the process.
3. UIApplication
UIApplication
Is the core of the application, each program must have an instance of UIApplication (or a subclass) at run time, and a pointer to this singleton instance can be obtained by [UIApplication Sharedapplication].
UIApplication
Helps manage the life cycle of an application, and it fulfills this task through delegate.
UIApplication
You can receive events, put all user events into a queue, process them one at a-it sends the current event to a suitable target control for processing. It also transfers some of the events to the delegate object to handle, delegate can handle events including: Application lifecycle events (such as program startup and shutdown), system events (such as incoming calls)
- (ibaction) Click {uiapplication*app = [uiapplicationSharedapplication];//Shadow Display status barApp. Statusbarhidden= No;//Set the number in the upper right corner of the iconApp. Applicationiconbadgenumber=0;//Set whether the network connection status needs to be displayedApp. Networkactivityindicatorvisible=YES;//call \ send SMS \ email \ Open Safari Browser Nsurl*url = [Nsurlurlwithstring:@"tel://10086"];Nsurl*url = [Nsurlurlwithstring:@"Http://www.baidu.com"]; [App Openurl:url];}
4. Appdelegate Agent (Life cycle callback)
??UIApplicationMain
The method generates the proxy for the application class according to the fourth parameter delegateClassName
(the class must adhere to the UIApplicationDelegate
protocol)and then set it to a UIApplication
. The method in the proxy is called when the application life cycle changes AppDelegate
.
@implementation mjappdelegate #pragma mark is called after the application is started (only once, and is only called when the program is opened for the first time)- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) launchoptions{}#pragma mark calls when the app enters the foreground- (void) Applicationwillenterforeground: (uiapplication*) application{}#pragma mark call when the app gets focus (activated)- (void) Applicationdidbecomeactive: (uiapplication*) application{}#pragma mark is called when the app loses focus (inactive)- (void) Applicationwillresignactive: (uiapplication*) application{}#pragma mark calls when the app enters the background- (void) Applicationdidenterbackground: (uiapplication*) application{}#pragma mark is called when the app is closed (prerequisites: When the app is running in the background)- (void) Applicationwillterminate: (uiapplication*) application{}@end
5. UIWindow
?? UIWindow is a special kind of uiview that typically has only one uiwindow in an app, but you can create multiple UIWindow manually.
UIWindow's main role:
①, providing a region to display the view
②, distributing events to a view
③ and Uiviewcontroller work together to facilitate equipment orientation rotation support
There are two common ways of adding UIView to UIWindow:
① addSubview
: Add UIView directly to UIWindow, the program is responsible for maintaining the UIView life cycle and refresh, but will not ignore UIView corresponding Uiviewcontroller
② rootViewController
: Automatically adds uiviewcontroller corresponding UIView to UIWindow, while maintaining Uiviewcontroller and UIView lifecycles
Common Methods
makeKeyWindow
: Make current UIWindow into Keywindow
makeKeyAndVisible
: Make the current UIWindow into Keywindow and show it
6. Uiviewcontroller Controller
?? Uiviewcontroller belongs to C (Controller) in the MVC model, and more specifically it is a view controller that manages a view (UIView).
?? A uiviewcontroller should only manage a view hierarchy, usually a full view hierarchy refers to a full screen. While many apps have different functions in full screen, some developers prefer to create a uiviewcontroller and a set of corresponding view to complete the function, which is completely out of line with Apple's design specifications.
Uiviewcontroller Life cycle methods:
①, when the view is loaded after the call viewdidload, here can make some data request or load, to update the interface
②, call viewwillappearwhen view is about to be added to view hierarchy, call viewdidappear when complete join
③, call viewwilldisappearwhen view is about to be removed from view hierarchy, call viewdiddisappear when the removal is complete
④, when memory is tight, call didreceivememorywarning, its default implementation is if the current Uiviewcontroller view of Superview is nil, Then release the view and call Viewdidunload, viewdidunload you can perform the subsequent memory cleanup (mainly the release of the interface element, which needs to be rebuilt when loading again)
(The view here refers to the Uiviewcontroller Internal view property)
7. Loading of the controller view
?? After the application is started, the agent's Application:didfinishlaunchingwithoptions: method is invoked, and the controller and view loading is done in this method.
?? The view of the controller Mjviewcontroller is deferred, and when the view is used, the controller's Loadview method is called to load the default procedure for View,loadview load view (the default implementation of Uiviewcontroller):
1> 如果nibName有值,就会加载对应的xib文件来创建view2> 如果nibName没有值 1) 优先加载MJView.xib文件来创建view 2) 加载MJViewController.xib文件来创建view 3) 如果没有找到上面所述的xib文件,就会用代码创建一个黑色的view
@implementation mjappdelegate - (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) launchoptions{ Self. Window= [[UIWindowAlloc] Initwithframe:[[uiscreen mainscreen] bounds];//Create controller (view of controller is delay load: load when used) Self. Viewcontroller= [[Mjviewcontroller alloc] initwithnibname:@"Mjviewcontroller"BundleNil];//If you execute the method below to set the view background, you will be called Loadview load view //self.viewcontroller.view.backgroundcolor = [Uicolor bluecolor]; //Set root controller (no view for root controller) Self. Window. Rootviewcontroller= Self. Viewcontroller;//Settings window visible (view is loaded at this time)[ Self. WindowMakekeyandvisible];return YES;}
@implementation mjviewcontroller #pragma mark if you do not override the Loadview,uiviewcontroller default implementation- (void) loadview{//should not call Super's Loadview //[Super Loadview]; //nslog (@ "---loadview"); //Dead Loop //self.view = [[Uiscrollview alloc] initWithFrame:self.view.frame]; //Return the frame that best fits the controller view CGRectframe = [UIScreen mainscreen]. Applicationframe;//nslog (@ "%@", Nsstringfromcgrect (frame)); Self. View= [[UiscrollviewAlloc] Initwithframe:frame]; Self. View. BackgroundColor= [UicolorYellowcolor];} */#pragma mark view is loaded and then called- (void) viewdidload{[SuperViewdidload];//Initialize child controls}@end
Common Files for iOS engineering
1. xxx-info.plist file
?? The most important document in the project describes the software name, software version, unique identifier, and so on, modifying the summery equivalent to modifying the file. Equivalent to Android manifest fileAndroidManifest.xml
??Bundle version
-Version number (this version number needs to be added each time a new version is posted to the App Store)
??Bundle display name
-Software name (limited to 10-12 characters, if exceeded, will be shown abbreviated name)
??Localiztion native development region
-Localization related
??Icon file
-app icon name, typically Icon.png
??Main nib file base name
-The name of the main nib file
??Bundle identifier
-Unique identification of the project, deployed to the real machine
?? ...
Note: in Xcode3, the filename is called: info.plist, so we don't name Info or info.plist when we create the. plist file.
2. Infoplist.strings
?? Internationalization-related configuration
3. Xxx-prefix.pch
?? In general, you can put some of the most frequently used header files in the project here to import, the entire project can access the content of this file, which saves the time to manually add imports, but also help speed up the compilation. Macros defined here can be accessed throughout the project.
?? Example: Add the following preprocessing directives to the PCH file, and then use the log (...) in the project. To output the log information, the NSLog statement can be removed at once when the application is published (debug mode is defined)
/* 如果软件处于调试状态,系统会默认定义一个叫做DEBUG的宏; 如果软件处于发布打包状态,系统就不会定义DEBUG这个宏 */#ifdef DEBUG// 调试状态:将MJLog替换成NSLog#define MJLog(...) NSLog(__VA_ARGS__)#else// 发布状态:将MJLog替换成空#define MJLog(...) #endif
4. Default.png
?? The application will display a full screen image called Default.png during startup, and the different screen resolutions will load different images, if not found, the closest one will be used (System auto-recognition)
Default.png
320x480
[email protected]
640x960
[email protected]
640x1136
5. Icon.png
?? Application icon
?? Apple Official document Search "app icon" –>app Icons on IPad and iphone
??
iOS application engineering files and start-up process