What exactly is happening when I tap my iPhone app icon?
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 Default@2x.png.
Can someone tell me what is loading when I tap the icon? Is it the method applicationDidFinishLaunching? Or the res开发者_运维知识库ources?
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.
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.
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.
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.
精彩评论