iPhone应用程序启动时间,生命周期问题 [英] iPhone app launch time, lifecycle question

查看:73
本文介绍了iPhone应用程序启动时间,生命周期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一种方法,以确定用户点击应用程序图标后需要多长时间才能使应用程序准备好供用户输入.

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.

据我所知,我可以插入要运行的代码的第一个位置是main.m中的main()函数,在接受用户输入之前完成的最后一件事是在应用程序委托中调用applicationDidFinishLaunching.但是,我发现在应用启动后几秒钟没有调用main(),并且不知道为什么.

As far as I know, the first place I can insert code to be run is the main() function in main.m, and the last thing that is done before user input is accepted is call applicationDidFinishLaunching in the app delegate. However, I'm finding that main() isn't called for several seconds after app launch, and can't figure out why.

我对应用程序生命周期的理解正确吗?在生命周期的早期,我可以开始测量此信息了吗?有人有解决办法吗?

Is my understanding of the app life cycle correct? Is there some place earlier in the life cycle I can start measuring this info? Anybody have a solution?

推荐答案

在调用main之前发生了几件事:

Several things happen before main is called:

  • 分配了地址空间(用于堆栈,可执行文件……)
  • 可执行文件已加载
  • 进程已链接到dyld(动态链接器)
  • 在mach标头中执行
  • load命令(加载框架和库)
  • 更多页面分配给库的静态存储
  • dyld执行符号解析
  • 执行库和可执行文件的初始化
  • 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

这仅应列举一些在调用main之前发生的事情.您可以将代码放在其中一个初始化函数中,以便能够在main之前做一些事情,但是不要期望这会大大减少tap和代码之间的延迟.

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.

您可以像这样在main之前声明要调用的C函数:

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

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

如果您需要做Objective-C的事情,则可以在您的一个类中实现+initialize.

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

这篇关于iPhone应用程序启动时间,生命周期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆