I have a few apps that I am trying to develop a reusable URL connection layer. I h开发者_Go百科ave done some research and am struggling between architectures. Specifically the APIs this layer utilizes.
In the past, I have used NSURLConnection
and NSOperation
on a separate RunLoop. This seems overkill. I've seen libraries that subclass NSURLConnection
. Others have a singleton Engine object that manages all requests.
The Engine and/or NSURLConnection
seem best to me. But I am asking for input before I go too far down one road. My goals would be:
- Ability to cancel a request
- Concurrent requests
- Non-blocking
- Data object of current open requests
Any direction or existing references with code samples would be greatly appreciated.
I'm not sure about a "data object of current open requests", but ASIHTTPRequest does the first three and is very easy to use.
Update
Actually, it looks like ASINetworkQueue may fulfill your last bullet point.
I personally use a singleton engine with my large Apps though it might not always be the best case. All the URL's I use require signing in first, figured it would be best if one Class handles all of the requests to prevent multiple URLS from signing into the one location.
I basically create a protocol for all my different connection classes into my singleton and pass the delegate of both the calling class and the singleton into it. If an error occurs its passed to the singleton so it can deal with it, if it completes it returns the data to the calling class.
精彩评论