<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLConnectionDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLConnectionDelegate"
  },
  "title" : "NSURLConnectionDelegate"
}
-->

# NSURLConnectionDelegate

A protocol that delegates of a URL connection implement to receive status about and provide feedback to the connection object.

```
protocol NSURLConnectionDelegate : NSObjectProtocol
```

## Overview

Delegates of [`NSURLConnection`](/documentation/Foundation/NSURLConnection) objects should implement either the [`NSURLConnectionDataDelegate`](/documentation/Foundation/NSURLConnectionDataDelegate) or [`NSURLConnectionDownloadDelegate`](/documentation/Foundation/NSURLConnectionDownloadDelegate) protocol in addition to the [`NSURLConnectionDelegate`](/documentation/Foundation/NSURLConnectionDelegate) protocol. Specifically:

- If you are using [`NSURLConnection`](/documentation/Foundation/NSURLConnection) in conjunction with Newsstand Kit’s `download(with:)` method, the delegate class should implement the [`NSURLConnectionDownloadDelegate`](/documentation/Foundation/NSURLConnectionDownloadDelegate) protocol.
- Otherwise, the delegate class should implement the [`NSURLConnectionDataDelegate`](/documentation/Foundation/NSURLConnectionDataDelegate) protocol.

Delegates that wish to perform custom authentication handling should implement the [`connection(_:willSendRequestFor:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:willSendRequestFor:)) method, which is the preferred mechanism for responding to authentication challenges. (See [`URLAuthenticationChallenge`](/documentation/Foundation/URLAuthenticationChallenge) for more information on authentication challenges.) If [`connection(_:willSendRequestFor:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:willSendRequestFor:)) is not implemented, the older, deprecated methods [`connection(_:canAuthenticateAgainstProtectionSpace:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:canAuthenticateAgainstProtectionSpace:)), [`connection(_:didReceive:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didReceive:)), and [`connection(_:didCancel:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didCancel:)) are called instead.

The [`connection(_:didFailWithError:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didFailWithError:)) method is called at most once if an error occurs during the loading of a resource. The [`connectionShouldUseCredentialStorage(_:)`](/documentation/Foundation/NSURLConnectionDelegate/connectionShouldUseCredentialStorage(_:)) method is called once, just before the loading of a resource begins.

## Topics

### Connection Authentication

[`-  connection:willSendRequestForAuthenticationChallenge:`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:willSendRequestFor:))

Tells the delegate that the connection will send a request for an authentication challenge.

[`-  connection:canAuthenticateAgainstProtectionSpace:`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:canAuthenticateAgainstProtectionSpace:))

Sent to determine whether the delegate is able to respond to a protection space’s form of authentication.

[`-  connection:didCancelAuthenticationChallenge:`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didCancel:))

Sent when a connection cancels an authentication challenge.

[`-  connection:didReceiveAuthenticationChallenge:`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didReceive:))

Sent when a connection must authenticate a challenge in order to download its request.

[`-  connectionShouldUseCredentialStorage:`](/documentation/Foundation/NSURLConnectionDelegate/connectionShouldUseCredentialStorage(_:))

Sent to determine whether the URL loader should use the credential storage for authenticating the connection.

### Connection Completion

[`-  connection:didFailWithError:`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didFailWithError:))

Sent when a connection fails to load its request successfully.

## Relationships

### Inherited By

[`NSURLConnectionDownloadDelegate`](/documentation/Foundation/NSURLConnectionDownloadDelegate)

[`NSURLConnectionDataDelegate`](/documentation/Foundation/NSURLConnectionDataDelegate)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)