When using NSURLConnection for asynchronous communication, you need the thread that it was created to connect to its RunLoop connection to have this thread polling for the same connection delegation method.
The correct way to create an NSURLConnection is asynchronous without relying on the RunLoop of the main thread below:
Where "TheConnection" is a member variable of the current class of type "NSURLConnection". In addition, you will need to create an NSOperationQueue member variable to manage delegate callbacks as soon as your connection receives a response. These calls will be transferred asynchronously back to the thread on which the connection is being made.
From there, you can return data using the appropriate delegate methods of NSURLConnection.
The advantage of using Grand Central Dispatch or operation queues for your threads is that Threading and RunLoop mechanics are already built-in; You do not have to manually allocate an extra thread with your own RunLoop inside it. This eliminates the two-step redundancy of creating a background thread for managing asynchronous server calls.
I hope this is enough for you to create a truly asynchronous network model for your application on the right path. :)
user298261
source share