Ios App Starting Point

if you write something in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"Starting point 1"); } 

main.m

  int main(int argc,char * argv[]) { ...... NSLog(@"Starting point 0"); } 

Which one is more useful main.m or appDelegate.m alone and in which scenerio.

+6
source share
3 answers

This is an interesting article that explains the sequence of launching the application.

http://oleb.net/blog/2011/06/app-launch-sequence-ios/

As a summary of the article, the conclusion is:

Beyond the application: didFinishLaunchingWithOptions: there are several entry points for custom code at run time (none of them are usually required):

Directly in main() before calling UIApplicationMain() . The init method for the custom subclass of UIApplication. The initWithCoder: or awakeFromNib methods of our application are delegated if it is created from a NIB file (by default). The + initialize methods of our application delegation class or a custom subclass of UIApplication. Any class receives a + initialize message before sending its first message from the program.

Note that this sequence only runs when the application is actually launched. If the application is already running and just returned from the background, none of this happens.

+6
source

You should use UIApplicationDelegate , not main.m

The didFinishedLaunching method is a good (but not the only) starting point.

Only there are you sure that all the specific iOS codes are loaded correctly. Basically, the load could have an error, the line will be executed mainly, but not in the didFinishedLaunching method.

0
source

The main () method is the very first thing that is called in terms of iOS applications, but the general rule is never to touch the main () function in iOS programming. - (BOOL) application: (UIApplication *) didFinishLaunchingWithOptions (NSDictionary *) launchOptions application occurs after the application starts successfully and should be used for any processes that need to be executed at the beginning of the application.

0
source

All Articles