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

# URLSessionDelegate

A protocol that defines methods that URL session instances call on their delegates to handle session-level events, like session life cycle changes.

```
protocol URLSessionDelegate : NSObjectProtocol, Sendable
```

## Overview

In addition to the methods defined in this protocol, most delegates should also implement some or all of the methods in the [`URLSessionTaskDelegate`](/documentation/Foundation/URLSessionTaskDelegate), [`URLSessionDataDelegate`](/documentation/Foundation/URLSessionDataDelegate), and [`URLSessionDownloadDelegate`](/documentation/Foundation/URLSessionDownloadDelegate) protocols to handle task-level events. These include events like the beginning and end of individual tasks, and periodic progress updates from data or download tasks.

> Note:
> Your ``doc://com.apple.foundation/documentation/Foundation/URLSession`` object doesn’t need to have a delegate. If no delegate is assigned, a system-provided delegate is used, and you must provide a completion callback to obtain the data.

## Topics

### Handling session life cycle changes

[`urlSession(_:didBecomeInvalidWithError:)`](/documentation/Foundation/URLSessionDelegate/urlSession(_:didBecomeInvalidWithError:))

Tells the URL session that the session has been invalidated.

[`urlSessionDidFinishEvents(forBackgroundURLSession:)`](/documentation/Foundation/URLSessionDelegate/urlSessionDidFinishEvents(forBackgroundURLSession:))

Tells the delegate that all messages enqueued for a session have been delivered.

### Handling authentication challenges

[`urlSession(_:didReceive:completionHandler:)`](/documentation/Foundation/URLSessionDelegate/urlSession(_:didReceive:completionHandler:))

Requests credentials from the delegate in response to a session-level authentication request from the remote server.

[`URLSession.AuthChallengeDisposition`](/documentation/Foundation/URLSession/AuthChallengeDisposition)

Constants passed by session or task delegates to the provided continuation block in response to an authentication challenge.



---

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)
