0

How can I observe when an NSURLConnection is cancelled?

I have a method.

- [TSMWebServer sendPage: withArguments: etc...]

The sendPage method returns an "NSURLConnection" pointer. I need the webserver to notice when the NSURLConnection is cancelled. Is there a way to observe when the "NSURLConnection" is cancelled using "NSNotificationCenter" ? I know I could return an "NSInvocation" or some kind of block which cancels connection and signals the "TSMWebServer" object, (the object, not the actual webserver), but I might need more power later, and observing the "NSURLConnection" being cancelled seems better to me. As well, I could return a wrapper object, but that seems like a bunch of unneeded work.

P.S. I'm finding it hard to find the right notifications sometimes. Is there no place in the iOS documentation which lists all notifications used in the standard library?

  • What do you mean by cancelled? The NSURLConnectionDownloadDelegate will call the the didFailWithError: if there is any problems such as time-out or bad URL. – Hubert Kunnemeyer Apr 26 '12 at 22:56
  • "[myConnection cancel];" is what I mean. That does not call back "didFailWithError:" . – Molly Stewart-Gallus Apr 27 '12 at 00:45
  • If your canceling it yourself with [myConnection cancel]. If it is necessary to know when your method gets fired, create and send a notification yourself.Or use delegation or better yet create callback block^. – Hubert Kunnemeyer Apr 27 '12 at 18:02

1 Answers1

1

An NSURLConnection will only cancel if you send it the cancel message. So if you send it the cancel message, you can tell yourself that you're canceling it, and thus there's no need for observation.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498