当我点击 iPhone 应用程序图标时到底发生了什么?
我的应用程序加载时间非常长,我不知道为什么。添加:它在主屏幕上卡住了 3-4 秒,然后才实际调出 [email ] ;受保护]。
有人可以告诉我点击图标时正在加载什么吗?是applicationDidFinishLaunching方法吗?还是资源?
My app takes incredibly long to load, and I have no idea why. To add: It gets stuck on the homescreen for 3-4 seconds before actually bringing up the [email protected].
Can someone tell me what is loading when I tap the icon? Is it the method applicationDidFinishLaunching? Or the resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作为一个非常笼统的答案:Apple 在 iOS 应用程序编程指南的应用程序生命周期。
值得注意的是本节中的第一个图表。介绍性段落后面的流程图相当不言自明(强调我的目的是为了解决您的具体问题):
至于为什么你的应用程序加载缓慢,你没有提供任何其他信息,所以我只能说检查你的笔尖中正在加载哪些资源,
并查看您的应用委托的
application:didFinishLaunchingWithOptions:
方法及其可能调用的相关设置例程,如果您有任何数据加载例程,它们是否会一切 在应用程序的文档目录中(例如)并将它们一下子加载到内存中?
您的数据是如何存储的?平面/简单文件(例如 XML 或 plist)可能听起来没什么大不了的,因为它们只是基本的 I/O,但当涉及大型数据存储或复杂的对象关系时,Core Data 或 SQLite 往往性能更优越。
此外,Instruments 也是您的朋友。
As a very general answer: Apple details this in the section The Application Life Cycle of the iOS Application Programming Guide.
Of note is the first diagram from the section. Fairly self-explanatory flowchart that follows the introductory paragraph (emphasis mine to address your specific query):
As to why your application is loading slowly, you don't provide any other information so all I can say is to check what resources are being loaded in your nibs,
And look at your app delegate's
application:didFinishLaunchingWithOptions:
method and the relevant setup routines that it may call,if you have any data-loading routines, are they taking everything in your application's documents directory (for example) and loading them into memory in one fell swoop?
how is your data stored? Flat/simple files (e.g. XML or plists) may not sound like a big deal since they're just basic I/O, but when it comes to large data stores or complex object relationships, Core Data or SQLite tend to be performantly superior.
Also, Instruments is your friend.
XCode 附带了一些非常棒的内置分析工具。作为第一步,我将使用仪器启动您的应用程序并分析初始化代码,这将是发现您在哪里消耗时间的最快方法。
了解如何使用这些工具的最佳方法是阅读 Apple 的可用文档 此处
尝试了解应用程序启动过程也是一个好主意,我写了一个简短的博客条目此处希望能有所帮助。
XCode comes with some pretty awesome profiling tools built-in. As a first step I'd launch your app with instruments and profile the initialization code, this will be the quickest way to discover where you're eating up time.
The best way to learn how to use the tools is to have a read over Apple's documentation available here
It's also a good idea to try and gain an understanding on the application launch process, I've written a short blog entry here which will hopefully help.
据我了解,资源是由您自己手动加载的,或者是在您从 .nib 文件加载视图时加载的。
不确定,但认为应用程序启动时会加载框架
可能您的第一个屏幕包含很多项目,因此需要加载。
applicationDidFinishLaunching
在应用程序启动后调用。As i understand the resources are loaded manually by yourself or when your are loading view from .nib files.
Not sure, but think frameworks are loaded when the app starts
Possibly your fist screen contains a lot of items and so there are loading.
applicationDidFinishLaunching
is called after the application is launched.至少,操作系统会加载您的窗口、初始视图控制器和视图 xib、它们包含的任何图像,并运行视图控制器、视图和/或应用程序委托所需的任何初始化代码。
如果您想要真正快速启动,请使用非常简单的初始窗口视图,稍后加载图像(声音等),并将所需的任何其他初始化(网络访问、数据库加载等)推送到后台线程中。
At minimum, the OS is loading your window, initial view controller and view xibs, any images which they contain, and running any initialization code which the view controller, views, and/or app delegate requires.
If you want a really fast launch, use a really plain initial window view, load images (sounds, etc.) later, and push any other initialization required (network access, database loading, etc.) into a background thread.