Mac Developer Library

Developer

Foundation Framework Reference NSURLConnectionDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSURLConnectionDelegate

The NSURLConnectionDelegate protocol defines methods common to the NSURLConnectionDataDelegate and NSURLConnectionDownloadDelegate protocols.

Delegates of NSURLConnection objects should implement either the data or download delegate protocol (including the methods described in this protocol). Specifically:

  • If you are using NSURLConnection in conjunction with Newsstand Kit’s downloadWithDelegate: method, the delegate class should implement the NSURLConnectionDownloadDelegate protocol.

  • Otherwise, the delegate class should implement the NSURLConnectionDataDelegate protocol.

Delegates that wish to perform custom authentication handling should implement the connection:willSendRequestForAuthenticationChallenge: method, which is the preferred mechanism for responding to authentication challenges. (See NSURLAuthenticationChallenge Class Reference for more information on authentication challenges.) If connection:willSendRequestForAuthenticationChallenge: is not implemented, the older, deprecated methods connection:canAuthenticateAgainstProtectionSpace:, connection:didReceiveAuthenticationChallenge:, and connection:didCancelAuthenticationChallenge: are called instead.

The connection:didFailWithError: method is called at most once if an error occurs during the loading of a resource. The connectionShouldUseCredentialStorage: method is called once, just before the loading of a resource begins.

Inheritance


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.7 and later.
  • Sent when a connection fails to load its request successfully.

    Declaration

    Swift

    optional func connection(_ connection: NSURLConnection, didFailWithError error: NSError)

    Objective-C

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

    Parameters

    connection

    The connection sending the message.

    error

    An error object containing details of why the connection failed to load the request successfully.

    Discussion

    Once the delegate receives this message, it will receive no further messages for connection.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.7.