当我点击 iPhone 应用程序图标时到底发生了什么?

发布于 2024-10-21 18:34:18 字数 270 浏览 2 评论 0原文

我的应用程序加载时间非常长,我不知道为什么。添加:它在主屏幕上卡住了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若水微香 2024-10-28 18:34:18

作为一个非常笼统的答案:Apple 在 iOS 应用程序编程指南的应用程序生命周期

值得注意的是本节中的第一个图表。介绍性段落后面的流程图相当不言自明(强调我的目的是为了解决您的具体问题):

应用程序生命周期由应用程序启动和终止之间发生的事件序列组成。在 iOS 中,用户通过点击主屏幕上的图标来启动您的应用程序。点击发生后不久,系统会显示一些过渡图形,并通过调用其 main 函数继续启动您的应用程序。 从现在开始,大部分初始化工作将移交给 UIKit,它会加载应用程序的主 nib 文件并准备好事件循环。

“”
(来源:apple.com< /a>)


至于为什么你的应用程序加载缓慢,你没有提供任何其他信息,所以我只能说检查你的笔尖中正在加载哪些资源,

  • 图像是否很大,或者是有很多吗?

并查看您的应用委托的 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):

The application life cycle constitutes the sequence of events that occurs between the launch and termination of your application. In iOS, the user launches your application by tapping its icon on the Home screen. Shortly after the tap occurs, the system displays some transitional graphics and proceeds to launch your application by calling its main function. From this point on, the bulk of the initialization work is handed over to UIKit, which loads the application’s main nib file and readies the event loop.


(source: apple.com)

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,

  • are the images very large, or are there many of them?

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.

少年亿悲伤 2024-10-28 18:34:18

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.

哥,最终变帅啦 2024-10-28 18:34:18

据我了解,资源是由您自己手动加载的,或者是在您从 .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.

妄断弥空 2024-10-28 18:34:18

至少,操作系统会加载您的窗口、初始视图控制器和视图 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文