iPhone app launch time, lifecycle question

前端 未结 4 532
别跟我提以往
别跟我提以往 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: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.

提交回复
热议问题