Protocol: NSURLConnectionDelegate
Overview
The NSURLConnectionDelegate protocol defines the optional methods implemented by delegates of NSURLConnection objects. Sent to determine whether the delegate is able to respond to a protection space’s form of authentication.Sent when a connection cancels an authentication challenge.Sent when a connection fails to load its request successfully.Sent when a connection must authenticate a challenge in order to download its request.Called when an NSURLConnection needs to retransmit a request that has a body stream to provide a new, unopened stream.Tells the delegate that the connection will send a request for an authentication challenge.Sent to determine whether the URL loader should consult the credential storage for authenticating the connection.
Instance Method Summary (collapse)
-
- connection:canAuthenticateAgainstProtectionSpace:
Sent to determine whether the delegate is able to respond to a protection space’s form of authentication.
-
- connection:didCancelAuthenticationChallenge:
Sent when a connection cancels an authentication challenge.
-
- connection:didFailWithError:
Sent when a connection fails to load its request successfully.
-
- connection:didReceiveAuthenticationChallenge:
Sent when a connection must authenticate a challenge in order to download its request.
-
- connection:needNewBodyStream:
Called when an NSURLConnection needs to retransmit a request that has a body stream to provide a new, unopened stream.
-
- connection:willSendRequestForAuthenticationChallenge:
Tells the delegate that the connection will send a request for an authentication challenge.
-
- connectionShouldUseCredentialStorage:
Sent to determine whether the URL loader should consult the credential storage for authenticating the connection.
Instance Method Details
- (Boolean) connection(connection, canAuthenticateAgainstProtectionSpace:protectionSpace)
Sent to determine whether the delegate is able to respond to a protection space’s form of authentication. This method is called before connection:didReceiveAuthenticationChallenge:, allowing the delegate to inspect a protection space before attempting to authenticate against it. By returning YES, the delegate indicates that it can handle the form of authentication, which it does in the subsequent call to connection:didReceiveAuthenticationChallenge:. If the delegate returns NO, the system attempts to use the user’s keychain to authenticate. If your delegate does not implement this method and the protection space uses client certificate authentication or server trust authentication, the system behaves as if you returned NO. The system behaves as if you returned YES for all other authentication methods.
- (Object) connection(connection, didCancelAuthenticationChallenge:challenge)
Sent when a connection cancels an authentication challenge.
- (Object) connection(connection, didFailWithError:error)
Sent when a connection fails to load its request successfully. Once the delegate receives this message, it will receive no further messages for connection.
- (Object) connection(connection, didReceiveAuthenticationChallenge:challenge)
Sent when a connection must authenticate a challenge in order to download its request. This method gives the delegate the opportunity to determine the course of action taken for the challenge: provide credentials, continue without providing credentials, or cancel the authentication challenge and the download.The delegate can determine the number of previous authentication challenges by sending the message previousFailureCount to challenge.If the previous failure count is 0 and the value returned by proposedCredential is nil, the delegate can create a new NSURLCredential object, providing information specific to the type of credential, and send a useCredential:forAuthenticationChallenge: message to [challenge sender], passing the credential and challenge as parameters. If proposedCredential is not nil, the value is a credential from the URL or the shared credential storage that can be provided to the user as feedback.The delegate may decide to abandon further attempts at authentication at any time by sending [challenge sender] a continueWithoutCredentialForAuthenticationChallenge: or a cancelAuthenticationChallenge: message. The specific action is implementation dependent.If the delegate implements this method, the download will suspend until [challenge sender] is sent one of the following messages: useCredential:forAuthenticationChallenge:, continueWithoutCredentialForAuthenticationChallenge: or cancelAuthenticationChallenge:.If the delegate does not implement this method the default implementation is used. If a valid credential for the request is provided as part of the URL, or is available from the NSURLCredentialStorage the [challenge sender] is sent a useCredential:forAuthenticationChallenge: with the credential. If the challenge has no credential or the credentials fail to authorize access, then continueWithoutCredentialForAuthenticationChallenge: is sent to [challenge sender] instead.
- (NSInputStream) connection(connection, needNewBodyStream:request, NS_AVAILABLE)
Called when an NSURLConnection needs to retransmit a request that has a body stream to provide a new, unopened stream. On OS X, if this method is not implemented, body stream data is spooled to disk in case retransmission is required. This spooling may not be desirable for large data sets.By implementing this delegate method, the client opts out of automatic spooling, and must provide a new, unopened stream for each retransmission.
- (Object) connection(connection, willSendRequestForAuthenticationChallenge:challenge)
Tells the delegate that the connection will send a request for an authentication challenge. This method allows the delegate to make an informed decision about connection authentication at once. If the delegate implements this method, it has no need to implement connection:canAuthenticateAgainstProtectionSpace:, connection:didReceiveAuthenticationChallenge:, connectionShouldUseCredentialStorage:. In fact, these other methods are not invoked. In this method,you must invoke one of the challenge-responder methods (NSURLAuthenticationChallengeSender protocol):useCredential:forAuthenticationChallenge: continueWithoutCredentialForAuthenticationChallenge: cancelAuthenticationChallenge: performDefaultHandlingForAuthenticationChallenge:rejectProtectionSpaceAndContinueWithChallenge:You might also want to analyze challenge for the authentication scheme and the proposed credential before calling a NSURLAuthenticationChallengeSender method. You should never assume that a proposed credential is present. You can either create your own credential and respond with that, or you can send the proposed credential back. (Because this object is immutable, if you want to change it you must copy it and then modify the copy.)
- (Boolean) connectionShouldUseCredentialStorage(connection)
Sent to determine whether the URL loader should consult the credential storage for authenticating the connection. This method is called before any attempt to authenticate is made. By returning NO, the delegate tells the connection not to consult the credential storage and makes itself responsible for providing credentials for any authentication challenges. Not implementing this method is the same as returning YES. The delegate is free to consult the credential storage itself when it receives a connection:didReceiveAuthenticationChallenge: message.