---
title: URLSessionDelegate
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/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.

## Declaration

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

## Mentioned in

Fetching website data into memory Performing manual server trust authentication Downloading files in the background Uploading data to a website

## Overview

Overview In addition to the methods defined in this protocol, most delegates should also implement some or all of the methods in the URLSessionTaskDelegate, URLSessionDataDelegate, and 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 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:)](foundation/urlsessiondelegate/urlsession(_:didbecomeinvalidwitherror:).md)
- [urlSessionDidFinishEvents(forBackgroundURLSession:)](foundation/urlsessiondelegate/urlsessiondidfinishevents(forbackgroundurlsession:).md)

### Handling authentication challenges

- [urlSession(_:didReceive:completionHandler:)](foundation/urlsessiondelegate/urlsession(_:didreceive:completionhandler:).md)
- [URLSession.AuthChallengeDisposition](foundation/urlsession/authchallengedisposition.md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

### Inherited By

- [URLSessionDataDelegate](foundation/urlsessiondatadelegate.md)
- [URLSessionDownloadDelegate](foundation/urlsessiondownloaddelegate.md)
- [URLSessionStreamDelegate](foundation/urlsessionstreamdelegate.md)
- [URLSessionTaskDelegate](foundation/urlsessiontaskdelegate.md)
- [URLSessionWebSocketDelegate](foundation/urlsessionwebsocketdelegate.md)

## See Also

### Working with a delegate

- [delegate](foundation/urlsession/delegate.md)
- [URLSessionTaskDelegate](foundation/urlsessiontaskdelegate.md)
- [delegateQueue](foundation/urlsession/delegatequeue.md)
