views:

136

answers:

2

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?

+3  A: 

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.

Martin Gordon
Using performSelector:withObject:afterDelay, you are saying I should be safe regardless since the run loop is already going? But what if my method eats up to much time on the main thread - the OS will still kill it even if I'm using performSelector right? I believe the separate thread is probably the way to go.
4thSpace
No, using performSelector:withObject:afterDelay: will hit the run loop first and then perform the selector. The shutdown timer is killed once you've hit the run loop after applicationDidFinishLaunching
Martin Gordon
+1  A: 

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.

lyonanderson