• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async?


  • Subject: Re: NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async?
  • From: Ken Ferry <email@hidden>
  • Date: Fri, 21 Jan 2011 11:36:45 -0800

Hi Rick,

I thought I'd pass along a message from Quinn in Apple's DTS group on this
topic.  Also, fyi, <http://www.lists.apple.com/macnetworkprog> is better for
networking questions

-Ken

Doing your NSConnection stuff synchronously is a mistake, even if
> NSBlockOperation makes it easier.  There are three major issues:


> o resource usage -- Threads are expensive, so having a bunch of threads
> sitting around literally doing nothing is not a great idea.  This is major
> concern on iOS, much less so on Mac OS X.


> o cancellation -- It's hard to implement cancellation in this sort of
> setup.


> o no delegate -- +[NSURLConnection sendSynchronousRequest:...] does not
> provide you with a delegate, which means you can't handle authentication
> challenges.  This is a problem because, even if the HTTP resource itself is
> not protected, you might be behind an authenticating proxy.  On iOS there's
> no avoiding this; you have to handle authentication challenges.  On Mac OS X
> this is only a problem if the existing proxy credentials (in the keychain)
> are wrong.


> You can resolve all of these issues, and stay within the NSOperation
> universe, by using a concurrent operation that manages an async
> NSURLConnection.  The QHTTPOperation class is a good example of this.


> <http://developer.apple.com/library/mac/#samplecode/LinkedImageFetcher/>

<http://developer.apple.com/library/ios/#samplecode/MVCNetworking/>



On Thu, Jan 20, 2011 at 2:51 PM, Rick Mann <email@hidden> wrote:

> With the advent of code blocks and NSBlockOperation, it's a lot tidier, and
> easier, to write code using NSURLConnection, particularly in the presence of
> multiple operations. The approach is to use an NSBlockOperation and
> +[NSURLConnection
> sendSynchronousRequest:returningResponse:error:] to synchronously request a
> resource (which occurs on a separate thread).
>
> The alternative is to use the asynchronous methods, and then manage all the
> state necessary to keep track of multiple instances of the same request. I
> prefer the former approach, but does Apple still recommend the async
> approach? Or is there no real difference between the two?
>
> I'm running on iOS 4.x, on a single-core device, but I don't think these
> devices will remain single-core for long, and the same question applies to
> multicore Macs.
>
> Thanks,
> Rick
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async? (From: Rick Mann <email@hidden>)

  • Prev by Date: Prevent windows from opening multiple times
  • Next by Date: Re: Prevent windows from opening multiple times
  • Previous by thread: Re: NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async?
  • Next by thread: iOS Pass NSManagedObjectContext from my app delegate
  • Index(es):
    • Date
    • Thread