iPhone app launch time, lifecycle question

前端 未结 4 529
别跟我提以往
别跟我提以往 2021-01-16 10:35

I\'m trying come up with a method to determine how long after the user taps the app icon it takes for the app to be ready for user input.

As far as I know, the first

相关标签:
4条回答
  • 2021-01-16 11:18

    Without access to the SpringBoard (something that only Apple and owners of jailbroken phones have), you can't get a very precise measurement of launch time. If your phone is jailbroken you might be able to create a debug version of of your app and run it with the time command.

    On the other hand, nearly all of the launch time that's under your control as a programmer happens between main() and applicationDidFinishLaunching:. So that might be a good place to start anyway.

    0 讨论(0)
  • 2021-01-16 11:26

    main() should be the first thing called, but there may be other things the system is doing first (loading libraries and resources, copy things around, etc). You're on the right track with a main-to-applicationDidFinishLaunch:'ing measurement.

    0 讨论(0)
  • 2021-01-16 11:27

    Several things happen before main is called:

    • address space is allocated (for stack, executable, ...)
    • the executable is loaded
    • process is linked to dyld (the dynamic linker)
    • load commands in the mach header are performed (frameworks and libraries loaded)
    • more pages get allocated for static storage of libraries
    • dyld performs symbol resolving
    • initializations of libraries and the executable are performed

    This should only name a few of the things which happen before main gets called. You can put code in one of the initialization functions to be able to do something a little before main but don’t expect this to reduce the delay between tap and your code a lot.

    You can declare a C function to be called before main like this:

    void __attribute__ ((constructor)) my_init(void);
    

    If you need to do Objective-C things, you can implement +initialize in one of your classes.

    0 讨论(0)
  • 2021-01-16 11:34

    I'm guessing that you're seeing this delay when running your application via Xcode. Xcode has to set up a few things behind the scenes to grab console output, etc., which induces an initial delay on startup.

    My recommendation is to perform your application startup timings (from main() to -applicationDidFinishLaunching:) by launching the application manually on the device. Do this a few times to account for initial load artifacts. If you log your results to the console, you can then grab them using the Xcode organizer. I've seen much shorter startup timings when testing my applications this way.

    0 讨论(0)
提交回复
热议问题