Question

In my app delegate's applicationDidBecomeActive:, I check for validity of the user's login status, to throw up a login page if it fails. This check involves a network call, and my fear is that in poor network situations it may block the main UI, effectively making the app hang.

What happens from a timing perspective when the app becomes active? Do the contents of applicationDidBecomeActive: block/run on the main thread? Should I be doing this network call asynchronously (e.g. using GCD)?

Was it helpful?

Solution

The applicationDidBecomeActive method is called on the main thread like all UIKit methods. You must always make sure that you perform any long running processes or networking access in a background thread.

Use the asynchronous form of NSURLConnection or use GCD to perform the action on a background queue.

OTHER TIPS

You should not perform synchronous network operations in any of your application delegate applicationDid... methods (well, you shouldn't do synchronous network operations anywhere in your program). In fact, iOS will terminate your app if it takes a long time to respond to launch/background/resume events. The crash log will state that <Your app> failed to launch in time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top