4thSpace
4thSpace

Reputation: 44312

Is app startup time restriction limited to applicationDidFinishLaunching?

If my app shuts down because load time takes to long, can I move some code in or being called from applicationDidFinishLaunching into the RootViewController? Meaning, is the (shutdown) timer only looking at applicationDidFinishLaunching?

Upvotes: 2

Views: 574

Answers (2)

Martin Gordon
Martin Gordon

Reputation: 36389

I'm not 100% sure on this, but I believe the timer stops when control returns to the run loop and the application can accept user input, which is generally at the end of your applicationDidFinishLaunching method.

However, if you load a view in applicationDidFinishLaunching, and either your loadView or viewDidLoad takes a long time, you're app may be shutdown by the OS. Alternatively, you can call the method using -performSelector:withObject:afterDelay: with a delay of 0, and the method will be queued up in the run loop and run as soon as possible.

If you must do a lot of processing before you can hand over control to the user, you should look into performing that load on a background thread.

EDIT: Here's the relevant Technical Q&A.

Upvotes: 4

lyonanderson
lyonanderson

Reputation: 2035

In general any time consuming stuff should not be done on the main thread. You're applicationDidFinishingLaunching should return as quickly as possible. Both to prevent your app being killed by SpringBoard, but also as a nice experience for the user. Either use performSelector:withObject:afterDelay: or use NSOperations to move stuff out of the main thread.

Upvotes: 1

Related Questions