Question

Regarding "didFailWithError" and "connectionDidFinishLoading"

Can they both be called? Or its always one or the other?

Was it helpful?

Solution

No, they cannot be called at the same time.

After the delegate receives a message connection:didFailWithError:, it receives no further delegate messages for the specified connection.

If the connection succeeds in downloading the request, the delegate receives the connectionDidFinishLoading: message. The delegate will receive no further messages for the connection and the NSURLConnection object can be released.

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

OTHER TIPS

While not obvious, the docs make a statement that only one of these two will be called. It either finishes successfully and connectionDidFinishLoading is called, or it fails with an error and didFailWithError is called. You can find this in the NSURLConnectionDataDelegate docs for the **connection:willSendRequest:redirectResponse: method.

Edit: It looks like the answer from @erkanyildiz shows the better info from the docs.

From docs https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html

connectionDidFinishLoading:

Sent when a connection has finished loading successfully.

Successfully. Seems like always one or the other.

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