URLSession diff between Xcode 13.4.1 and 14.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreFoundation | |
/* NSURLSession.h | |
Copyright (c) 2013-2019, Apple Inc. All rights reserved. | |
*/ | |
/* | |
NSURLSession is a replacement API for NSURLConnection. It provides | |
options that affect the policy of, and various aspects of the | |
mechanism by which NSURLRequest objects are retrieved from the | |
network. | |
An NSURLSession may be bound to a delegate object. The delegate is | |
invoked for certain events during the lifetime of a session, such as | |
server authentication or determining whether a resource to be loaded | |
should be converted into a download. | |
NSURLSession instances are thread-safe. | |
The default NSURLSession uses a system provided delegate and is | |
appropriate to use in place of existing code that uses | |
+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] | |
An NSURLSession creates NSURLSessionTask objects which represent the | |
action of a resource being loaded. These are analogous to | |
NSURLConnection objects but provide for more control and a unified | |
delegate model. | |
NSURLSessionTask objects are always created in a suspended state and | |
must be sent the -resume message before they will execute. | |
Subclasses of NSURLSessionTask are used to syntactically | |
differentiate between data and file downloads. | |
An NSURLSessionDataTask receives the resource as a series of calls to | |
the URLSession:dataTask:didReceiveData: delegate method. This is type of | |
task most commonly associated with retrieving objects for immediate parsing | |
by the consumer. | |
An NSURLSessionUploadTask differs from an NSURLSessionDataTask | |
in how its instance is constructed. Upload tasks are explicitly created | |
by referencing a file or data object to upload, or by utilizing the | |
-URLSession:task:needNewBodyStream: delegate message to supply an upload | |
body. | |
An NSURLSessionDownloadTask will directly write the response data to | |
a temporary file. When completed, the delegate is sent | |
URLSession:downloadTask:didFinishDownloadingToURL: and given an opportunity | |
to move this file to a permanent location in its sandboxed container, or to | |
otherwise read the file. If canceled, an NSURLSessionDownloadTask can | |
produce a data blob that can be used to resume a download at a later | |
time. | |
Beginning with iOS 9 and Mac OS X 10.11, NSURLSessionStream is | |
available as a task type. This allows for direct TCP/IP connection | |
to a given host and port with optional secure handshaking and | |
navigation of proxies. Data tasks may also be upgraded to a | |
NSURLSessionStream task via the HTTP Upgrade: header and appropriate | |
use of the pipelining option of NSURLSessionConfiguration. See RFC | |
2817 and RFC 6455 for information about the Upgrade: header, and | |
comments below on turning data tasks into stream tasks. | |
An NSURLSessionWebSocketTask is a task that allows clients to connect to servers supporting | |
WebSocket. The task will perform the HTTP handshake to upgrade the connection | |
and once the WebSocket handshake is successful, the client can read and write | |
messages that will be framed using the WebSocket protocol by the framework. | |
*/ | |
/* DataTask objects receive the payload through zero or more delegate messages */ | |
/* UploadTask objects receive periodic progress updates but do not return a body */ | |
/* DownloadTask objects represent an active download to disk. They can provide resume data when canceled. */ | |
/* StreamTask objects may be used to create NSInput and NSOutputStreams, or used directly in reading and writing. */ | |
/* WebSocket objects perform a WebSocket handshake with the server and can be used to send and receive WebSocket messages */ | |
@available(iOS 7.0, *) | |
public let NSURLSessionTransferSizeUnknown: Int64 /* -1LL */ | |
@available(iOS 7.0, *) | |
open class URLSession : NSObject, @unchecked Sendable { | |
open class var shared: URLSession { get } | |
public /*not inherited*/ init(configuration: URLSessionConfiguration) | |
public /*not inherited*/ init(configuration: URLSessionConfiguration, delegate: URLSessionDelegate?, delegateQueue queue: OperationQueue?) | |
open var delegateQueue: OperationQueue { get } | |
open var delegate: URLSessionDelegate? { get } | |
@NSCopying open var configuration: URLSessionConfiguration { get } | |
open var sessionDescription: String? | |
open func finishTasksAndInvalidate() | |
open func invalidateAndCancel() | |
open func reset(completionHandler: @escaping @Sendable () -> Void) | |
open func reset() async | |
open func flush(completionHandler: @escaping @Sendable () -> Void) | |
open func flush() async | |
open func getTasksWithCompletionHandler(_ completionHandler: @escaping @Sendable ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask]) -> Void) | |
open var tasks: ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask]) { get async } | |
@available(iOS 9.0, *) | |
open func getAllTasks(completionHandler: @escaping @Sendable ([URLSessionTask]) -> Void) | |
@available(iOS 9.0, *) | |
open var allTasks: [URLSessionTask] { get async } | |
open func dataTask(with request: URLRequest) -> URLSessionDataTask | |
open func dataTask(with url: URL) -> URLSessionDataTask | |
open func uploadTask(with request: URLRequest, fromFile fileURL: URL) -> URLSessionUploadTask | |
open func uploadTask(with request: URLRequest, from bodyData: Data) -> URLSessionUploadTask | |
open func uploadTask(withStreamedRequest request: URLRequest) -> URLSessionUploadTask | |
open func downloadTask(with request: URLRequest) -> URLSessionDownloadTask | |
open func downloadTask(with url: URL) -> URLSessionDownloadTask | |
open func downloadTask(withResumeData resumeData: Data) -> URLSessionDownloadTask | |
@available(iOS 9.0, *) | |
open func streamTask(withHostName hostname: String, port: Int) -> URLSessionStreamTask | |
@available(iOS, introduced: 9.0, deprecated: 100000, message: "Use nw_connection_t in Network framework instead") | |
open func streamTask(with service: NetService) -> URLSessionStreamTask | |
@available(iOS 13.0, *) | |
open func webSocketTask(with url: URL) -> URLSessionWebSocketTask | |
@available(iOS 13.0, *) | |
open func webSocketTask(with url: URL, protocols: [String]) -> URLSessionWebSocketTask | |
@available(iOS 13.0, *) | |
open func webSocketTask(with request: URLRequest) -> URLSessionWebSocketTask | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use +[NSURLSession sessionWithConfiguration:] or other class methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use +[NSURLSession sessionWithConfiguration:] or other class methods to create instances") | |
open class func new() -> Self | |
} | |
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | |
extension URLSession { | |
/// Returns a publisher that wraps a URL session data task for a given URL. | |
/// | |
/// The publisher publishes data when the task completes, or terminates if the task fails with an error. | |
/// - Parameter url: The URL for which to create a data task. | |
/// - Returns: A publisher that wraps a data task for the URL. | |
public func dataTaskPublisher(for url: URL) -> URLSession.DataTaskPublisher | |
/// Returns a publisher that wraps a URL session data task for a given URL request. | |
/// | |
/// The publisher publishes data when the task completes, or terminates if the task fails with an error. | |
/// - Parameter request: The URL request for which to create a data task. | |
/// - Returns: A publisher that wraps a data task for the URL request. | |
public func dataTaskPublisher(for request: URLRequest) -> URLSession.DataTaskPublisher | |
public struct DataTaskPublisher : Publisher, Sendable { | |
/// The kind of values published by this publisher. | |
public typealias Output = (data: Data, response: URLResponse) | |
/// The kind of errors this publisher might publish. | |
/// | |
/// Use `Never` if this `Publisher` does not publish errors. | |
public typealias Failure = URLError | |
public let request: URLRequest | |
public let session: URLSession | |
public init(request: URLRequest, session: URLSession) | |
/// Attaches the specified subscriber to this publisher. | |
/// | |
/// Implementations of ``Publisher`` must implement this method. | |
/// | |
/// The provided implementation of ``Publisher/subscribe(_:)-4u8kn``calls this method. | |
/// | |
/// - Parameter subscriber: The subscriber to attach to this ``Publisher``, after which it can receive values. | |
public func receive<S>(subscriber: S) where S : Subscriber, S.Failure == URLError, S.Input == (data: Data, response: URLResponse) | |
} | |
} | |
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) | |
extension URLSession { | |
/// Convenience method to load data using an URLRequest, creates and resumes an URLSessionDataTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to load data. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data and response. | |
public func data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) | |
/// Convenience method to load data using an URL, creates and resumes an URLSessionDataTask internally. | |
/// | |
/// - Parameter url: The URL for which to load data. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data and response. | |
public func data(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) | |
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to upload data. | |
/// - Parameter fileURL: File to upload. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data and response. | |
public func upload(for request: URLRequest, fromFile fileURL: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) | |
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to upload data. | |
/// - Parameter bodyData: Data to upload. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data and response. | |
public func upload(for request: URLRequest, from bodyData: Data, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) | |
/// Convenience method to download using an URLRequest, creates and resumes an URLSessionDownloadTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to download. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Downloaded file URL and response. The file will not be removed automatically. | |
public func download(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (URL, URLResponse) | |
/// Convenience method to download using an URL, creates and resumes an URLSessionDownloadTask internally. | |
/// | |
/// - Parameter url: The URL for which to download. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Downloaded file URL and response. The file will not be removed automatically. | |
public func download(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (URL, URLResponse) | |
/// Convenience method to resume download, creates and resumes an URLSessionDownloadTask internally. | |
/// | |
/// - Parameter resumeData: Resume data from an incomplete download. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Downloaded file URL and response. The file will not be removed automatically. | |
public func download(resumeFrom resumeData: Data, delegate: URLSessionTaskDelegate? = nil) async throws -> (URL, URLResponse) | |
/// AsyncBytes conforms to AsyncSequence for data delivery. The sequence is single pass. Delegate will not be called for response and data delivery. | |
public struct AsyncBytes : AsyncSequence, Sendable { | |
/// Underlying data task providing the bytes. | |
public var task: URLSessionDataTask { get } | |
/// The type of element produced by this asynchronous sequence. | |
public typealias Element = UInt8 | |
/// The type of asynchronous iterator that produces elements of this | |
/// asynchronous sequence. | |
public typealias AsyncIterator = URLSession.AsyncBytes.Iterator | |
@frozen public struct Iterator : AsyncIteratorProtocol, Sendable { | |
public typealias Element = UInt8 | |
/// Asynchronously advances to the next element and returns it, or ends the | |
/// sequence if there is no next element. | |
/// | |
/// - Returns: The next element, if it exists, or `nil` to signal the end of | |
/// the sequence. | |
@inlinable public mutating func next() async throws -> UInt8? | |
} | |
/// Creates the asynchronous iterator that produces elements of this | |
/// asynchronous sequence. | |
/// | |
/// - Returns: An instance of the `AsyncIterator` type used to produce | |
/// elements of the asynchronous sequence. | |
public func makeAsyncIterator() -> URLSession.AsyncBytes.Iterator | |
} | |
/// Returns a byte stream that conforms to AsyncSequence protocol. | |
/// | |
/// - Parameter request: The URLRequest for which to load data. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data stream and response. | |
public func bytes(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (URLSession.AsyncBytes, URLResponse) | |
/// Returns a byte stream that conforms to AsyncSequence protocol. | |
/// | |
/// - Parameter url: The URL for which to load data. | |
/// - Parameter delegate: Task-specific delegate. | |
/// - Returns: Data stream and response. | |
public func bytes(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (URLSession.AsyncBytes, URLResponse) | |
} | |
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | |
extension URLSession { | |
/// Convenience method to load data using an URLRequest, creates and resumes an URLSessionDataTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to load data. | |
/// - Returns: Data and response. | |
public func data(for request: URLRequest) async throws -> (Data, URLResponse) | |
/// Convenience method to load data using an URL, creates and resumes an URLSessionDataTask internally. | |
/// | |
/// - Parameter url: The URL for which to load data. | |
/// - Returns: Data and response. | |
public func data(from url: URL) async throws -> (Data, URLResponse) | |
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to upload data. | |
/// - Parameter fileURL: File to upload. | |
/// - Returns: Data and response. | |
public func upload(for request: URLRequest, fromFile fileURL: URL) async throws -> (Data, URLResponse) | |
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally. | |
/// | |
/// - Parameter request: The URLRequest for which to upload data. | |
/// - Parameter bodyData: Data to upload. | |
/// - Returns: Data and response. | |
public func upload(for request: URLRequest, from bodyData: Data) async throws -> (Data, URLResponse) | |
} | |
/* | |
* NSURLSession convenience routines deliver results to | |
* a completion handler block. These convenience routines | |
* are not available to NSURLSessions that are configured | |
* as background sessions. | |
* | |
* Task objects are always created in a suspended state and | |
* must be sent the -resume message before they will execute. | |
*/ | |
extension URLSession { | |
/* | |
* data task convenience methods. These methods create tasks that | |
* bypass the normal delegate calls for response and data delivery, | |
* and provide a simple cancelable asynchronous interface to receiving | |
* data. Errors will be returned in the NSURLErrorDomain, | |
* see <Foundation/NSURLError.h>. The delegate, if any, will still be | |
* called for authentication challenges. | |
*/ | |
open func dataTask(with request: URLRequest, completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask | |
open func dataTask(with url: URL, completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask | |
/* | |
* upload convenience method. | |
*/ | |
open func uploadTask(with request: URLRequest, fromFile fileURL: URL, completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionUploadTask | |
open func uploadTask(with request: URLRequest, from bodyData: Data?, completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionUploadTask | |
/* | |
* download task convenience methods. When a download successfully | |
* completes, the NSURL will point to a file that must be read or | |
* copied during the invocation of the completion routine. The file | |
* will be removed automatically. | |
*/ | |
open func downloadTask(with request: URLRequest, completionHandler: @escaping @Sendable (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask | |
open func downloadTask(with url: URL, completionHandler: @escaping @Sendable (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask | |
open func downloadTask(withResumeData resumeData: Data, completionHandler: @escaping @Sendable (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask | |
} | |
extension URLSessionTask { | |
@available(iOS 7.0, *) | |
public enum State : Int, @unchecked Sendable { | |
case running = 0 | |
case suspended = 1 | |
case canceling = 2 | |
case completed = 3 | |
} | |
/* | |
* NSURLSessionTask - a cancelable object that refers to the lifetime | |
* of processing a given request. | |
*/ | |
/* an identifier for this task, assigned by and unique to the owning session */ | |
/* may be nil if this is a stream task */ | |
/* may differ from originalRequest due to http server redirection */ | |
/* may be nil if no response has been received */ | |
/* Sets a task-specific delegate. Methods not implemented on this delegate will | |
* still be forwarded to the session delegate. | |
* | |
* Cannot be modified after task resumes. Not supported on background session. | |
* | |
* Delegate is strongly referenced until the task completes, after which it is | |
* reset to `nil`. | |
*/ | |
/* | |
* NSProgress object which represents the task progress. | |
* It can be used for task progress tracking. | |
*/ | |
/* | |
* Start the network load for this task no earlier than the specified date. If | |
* not specified, no start delay is used. | |
* | |
* Only applies to tasks created from background NSURLSession instances; has no | |
* effect for tasks created from other session types. | |
*/ | |
/* | |
* The number of bytes that the client expects (a best-guess upper-bound) will | |
* be sent and received by this task. These values are used by system scheduling | |
* policy. If unspecified, NSURLSessionTransferSizeUnknown is used. | |
*/ | |
/* Byte count properties may be zero if no body is expected, | |
* or NSURLSessionTransferSizeUnknown if it is not possible | |
* to know how many bytes will be transferred. | |
*/ | |
/* number of body bytes already sent */ | |
/* number of body bytes already received */ | |
/* number of body bytes we expect to send, derived from the Content-Length of the HTTP request */ | |
/* number of byte bytes we expect to receive, usually derived from the Content-Length header of an HTTP response. */ | |
/* | |
* The taskDescription property is available for the developer to | |
* provide a descriptive label for the task. | |
*/ | |
/* -cancel returns immediately, but marks a task as being canceled. | |
* The task will signal -URLSession:task:didCompleteWithError: with an | |
* error value of { NSURLErrorDomain, NSURLErrorCancelled }. In some | |
* cases, the task may signal other work before it acknowledges the | |
* cancelation. -cancel may be sent to a task that has been suspended. | |
*/ | |
/* | |
* The current state of the task within the session. | |
*/ | |
/* | |
* The error, if any, delivered via -URLSession:task:didCompleteWithError: | |
* This property will be nil in the event that no error occurred. | |
*/ | |
/* | |
* Suspending a task will prevent the NSURLSession from continuing to | |
* load data. There may still be delegate calls made on behalf of | |
* this task (for instance, to report data received while suspending) | |
* but no further transmissions will be made on behalf of the task | |
* until -resume is sent. The timeout timer associated with the task | |
* will be disabled while a task is suspended. -suspend and -resume are | |
* nestable. | |
*/ | |
/* | |
* Sets a scaling factor for the priority of the task. The scaling factor is a | |
* value between 0.0 and 1.0 (inclusive), where 0.0 is considered the lowest | |
* priority and 1.0 is considered the highest. | |
* | |
* The priority is a hint and not a hard requirement of task performance. The | |
* priority of a task may be changed using this API at any time, but not all | |
* protocols support this; in these cases, the last priority that took effect | |
* will be used. | |
* | |
* If no priority is specified, the task will operate with the default priority | |
* as defined by the constant NSURLSessionTaskPriorityDefault. Two additional | |
* priority levels are provided: NSURLSessionTaskPriorityLow and | |
* NSURLSessionTaskPriorityHigh, but use is not restricted to these. | |
*/ | |
/* Provides a hint indicating if incremental delivery of a partial response body | |
* would be useful for the application, or if it cannot process the response | |
* until it is complete. Indicating that incremental delivery is not desired may | |
* improve task performance. For example, if a response cannot be decoded until | |
* the entire content is received, set this property to false. | |
* | |
* Defaults to true unless this task is created with completion-handler based | |
* convenience methods, or if it is a download task. | |
*/ | |
@available(iOS 8.0, *) | |
public class let defaultPriority: Float | |
@available(iOS 8.0, *) | |
public class let lowPriority: Float | |
@available(iOS 8.0, *) | |
public class let highPriority: Float | |
} | |
@available(iOS 7.0, *) | |
open class URLSessionTask : NSObject, NSCopying, ProgressReporting, @unchecked Sendable { | |
open var taskIdentifier: Int { get } | |
open var originalRequest: URLRequest? { get } | |
open var currentRequest: URLRequest? { get } | |
@NSCopying open var response: URLResponse? { get } | |
@available(iOS 15.0, *) | |
open var delegate: URLSessionTaskDelegate? | |
@available(iOS 11.0, *) | |
open var progress: Progress { get } | |
@available(iOS 11.0, *) | |
open var earliestBeginDate: Date? | |
@available(iOS 11.0, *) | |
open var countOfBytesClientExpectsToSend: Int64 | |
@available(iOS 11.0, *) | |
open var countOfBytesClientExpectsToReceive: Int64 | |
open var countOfBytesSent: Int64 { get } | |
open var countOfBytesReceived: Int64 { get } | |
open var countOfBytesExpectedToSend: Int64 { get } | |
open var countOfBytesExpectedToReceive: Int64 { get } | |
open var taskDescription: String? | |
open func cancel() | |
open var state: URLSessionTask.State { get } | |
open var error: Error? { get } | |
open func suspend() | |
open func resume() | |
@available(iOS 8.0, *) | |
open var priority: Float | |
@available(iOS 14.5, *) | |
open var prefersIncrementalDelivery: Bool | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Not supported") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Not supported") | |
open class func new() -> Self | |
} | |
@available(iOS 7.0, *) | |
open class URLSessionDataTask : URLSessionTask, @unchecked Sendable { | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession dataTaskWithRequest:] or other NSURLSession methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession dataTaskWithRequest:] or other NSURLSession methods to create instances") | |
open class func new() -> Self | |
} | |
@available(iOS 7.0, *) | |
open class URLSessionUploadTask : URLSessionDataTask, @unchecked Sendable { | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession uploadTaskWithStreamedRequest:] or other NSURLSession methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession uploadTaskWithStreamedRequest:] or other NSURLSession methods to create instances") | |
open class func new() -> Self | |
} | |
@available(iOS 7.0, *) | |
open class URLSessionDownloadTask : URLSessionTask, @unchecked Sendable { | |
open func cancel(byProducingResumeData completionHandler: @escaping @Sendable (Data?) -> Void) | |
open func cancelByProducingResumeData() async -> Data? | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession downloadTaskWithRequest:] or other NSURLSession methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession downloadTaskWithRequest:] or other NSURLSession methods to create instances") | |
open class func new() -> Self | |
} | |
@available(iOS 9.0, *) | |
open class URLSessionStreamTask : URLSessionTask, @unchecked Sendable { | |
open func readData(ofMinLength minBytes: Int, maxLength maxBytes: Int, timeout: TimeInterval, completionHandler: @escaping @Sendable (Data?, Bool, Error?) -> Void) | |
open func readData(ofMinLength minBytes: Int, maxLength maxBytes: Int, timeout: TimeInterval) async throws -> (Data?, Bool) | |
open func write(_ data: Data, timeout: TimeInterval, completionHandler: @escaping @Sendable (Error?) -> Void) | |
open func write(_ data: Data, timeout: TimeInterval) async throws | |
open func captureStreams() | |
open func closeWrite() | |
open func closeRead() | |
open func startSecureConnection() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "TLS cannot be disabled once it is enabled") | |
open func stopSecureConnection() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession streamTaskWithHostName:port:] or other NSURLSession methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use -[NSURLSession streamTaskWithHostName:port:] or other NSURLSession methods to create instances") | |
open class func new() -> Self | |
} | |
extension URLSessionWebSocketTask { | |
@available(iOS 13.0, *) | |
public enum CloseCode : Int, @unchecked Sendable { | |
case invalid = 0 | |
case normalClosure = 1000 | |
case goingAway = 1001 | |
case protocolError = 1002 | |
case unsupportedData = 1003 | |
case noStatusReceived = 1005 | |
case abnormalClosure = 1006 | |
case invalidFramePayloadData = 1007 | |
case policyViolation = 1008 | |
case messageTooBig = 1009 | |
case mandatoryExtensionMissing = 1010 | |
case internalServerError = 1011 | |
case tlsHandshakeFailure = 1015 | |
} | |
} | |
@available(iOS 13.0, *) | |
open class URLSessionWebSocketTask : URLSessionTask, @unchecked Sendable { | |
open func sendPing(pongReceiveHandler: @escaping @Sendable (Error?) -> Void) | |
open func cancel(with closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) | |
open var maximumMessageSize: Int | |
open var closeCode: URLSessionWebSocketTask.CloseCode { get } | |
open var closeReason: Data? { get } | |
} | |
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | |
extension URLSessionWebSocketTask { | |
public enum Message : Sendable { | |
case data(Data) | |
case string(String) | |
} | |
public func send(_ message: URLSessionWebSocketTask.Message, completionHandler: @escaping (Error?) -> Void) | |
public func send(_ message: URLSessionWebSocketTask.Message) async throws | |
public func receive(completionHandler: @escaping (Result<URLSessionWebSocketTask.Message, Error>) -> Void) | |
public func receive() async throws -> URLSessionWebSocketTask.Message | |
} | |
extension URLSessionConfiguration { | |
/** | |
@enum NSURLSessionMultipathServiceType | |
@discussion The NSURLSessionMultipathServiceType enum defines constants that | |
can be used to specify the multipath service type to associate an NSURLSession. The | |
multipath service type determines whether multipath TCP should be attempted and the conditions | |
for creating and switching between subflows. Using these service types requires the appropriate entitlement. Any connection attempt will fail if the process does not have the required entitlement. | |
A primary interface is a generally less expensive interface in terms of both cost and power (such as WiFi or ethernet). A secondary interface is more expensive (such as 3G or LTE). | |
@constant NSURLSessionMultipathServiceTypeNone Specifies that multipath tcp should not be used. Connections will use a single flow. | |
This is the default value. No entitlement is required to set this value. | |
@constant NSURLSessionMultipathServiceTypeHandover Specifies that a secondary subflow should only be used | |
when the primary subflow is not performing adequately. Requires the com.apple.developer.networking.multipath entitlement. | |
@constant NSURLSessionMultipathServiceTypeInteractive Specifies that a secondary subflow should be used if the | |
primary subflow is not performing adequately (packet loss, high round trip times, bandwidth issues). The secondary | |
subflow will be created more aggressively than with NSURLSessionMultipathServiceTypeHandover. Requires the com.apple.developer.networking.multipath entitlement. | |
@constant NSURLSessionMultipathServiceTypeAggregate Specifies that multiple subflows across multiple interfaces should be | |
used for better bandwidth. This mode is only available for experimentation on devices configured for development use. | |
It can be enabled in the Developer section of the Settings app. | |
*/ | |
@available(iOS 11.0, *) | |
public enum MultipathServiceType : Int, @unchecked Sendable { | |
case none = 0 | |
case handover = 1 | |
case interactive = 2 | |
case aggregate = 3 | |
} | |
} | |
@available(iOS 7.0, *) | |
open class URLSessionConfiguration : NSObject, NSCopying, @unchecked Sendable { | |
open class var `default`: URLSessionConfiguration { get } | |
open class var ephemeral: URLSessionConfiguration { get } | |
@available(iOS 8.0, *) | |
open class func background(withIdentifier identifier: String) -> URLSessionConfiguration | |
open var identifier: String? { get } | |
open var requestCachePolicy: NSURLRequest.CachePolicy | |
open var timeoutIntervalForRequest: TimeInterval | |
open var timeoutIntervalForResource: TimeInterval | |
open var networkServiceType: NSURLRequest.NetworkServiceType | |
open var allowsCellularAccess: Bool | |
@available(iOS 13.0, *) | |
open var allowsExpensiveNetworkAccess: Bool | |
@available(iOS 13.0, *) | |
open var allowsConstrainedNetworkAccess: Bool | |
@available(iOS 16.0, *) | |
open var requiresDNSSECValidation: Bool | |
@available(iOS 11.0, *) | |
open var waitsForConnectivity: Bool | |
@available(iOS 7.0, *) | |
open var isDiscretionary: Bool | |
@available(iOS 8.0, *) | |
open var sharedContainerIdentifier: String? | |
@available(iOS 7.0, *) | |
open var sessionSendsLaunchEvents: Bool | |
open var connectionProxyDictionary: [AnyHashable : Any]? | |
@available(iOS, introduced: 7.0, deprecated: 100000) | |
open var tlsMinimumSupportedProtocol: SSLProtocol | |
@available(iOS, introduced: 7.0, deprecated: 100000) | |
open var tlsMaximumSupportedProtocol: SSLProtocol | |
@available(iOS 13.0, *) | |
open var tlsMinimumSupportedProtocolVersion: tls_protocol_version_t | |
@available(iOS 13.0, *) | |
open var tlsMaximumSupportedProtocolVersion: tls_protocol_version_t | |
open var httpShouldUsePipelining: Bool | |
open var httpShouldSetCookies: Bool | |
open var httpCookieAcceptPolicy: HTTPCookie.AcceptPolicy | |
open var httpAdditionalHeaders: [AnyHashable : Any]? | |
open var httpMaximumConnectionsPerHost: Int | |
open var httpCookieStorage: HTTPCookieStorage? | |
open var urlCredentialStorage: URLCredentialStorage? | |
open var urlCache: URLCache? | |
@available(iOS 9.0, *) | |
open var shouldUseExtendedBackgroundIdleMode: Bool | |
open var protocolClasses: [AnyClass]? | |
@available(iOS 11.0, *) | |
open var multipathServiceType: URLSessionConfiguration.MultipathServiceType | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use NSURLSessionConfiguration.defaultSessionConfiguration or other class methods to create instances") | |
public init() | |
@available(iOS, introduced: 7.0, deprecated: 13.0, message: "Please use NSURLSessionConfiguration.defaultSessionConfiguration or other class methods to create instances") | |
open class func new() -> Self | |
} | |
extension URLSession { | |
@available(iOS 11.0, *) | |
public enum DelayedRequestDisposition : Int, @unchecked Sendable { | |
case continueLoading = 0 | |
case useNewRequest = 1 | |
case cancel = 2 | |
} | |
@available(iOS 7.0, *) | |
public enum AuthChallengeDisposition : Int, @unchecked Sendable { | |
case useCredential = 0 /* Use the specified credential, which may be nil */ | |
case performDefaultHandling = 1 /* Default handling for the challenge - as if this delegate were not implemented; the credential parameter is ignored. */ | |
case cancelAuthenticationChallenge = 2 /* The entire request will be canceled; the credential parameter is ignored. */ | |
case rejectProtectionSpace = 3 /* This challenge is rejected and the next authentication protection space should be tried; the credential parameter is ignored. */ | |
} | |
@available(iOS 7.0, *) | |
public enum ResponseDisposition : Int, @unchecked Sendable { | |
case cancel = 0 /* Cancel the load, this is the same as -[task cancel] */ | |
case allow = 1 /* Allow the load to continue */ | |
case becomeDownload = 2 /* Turn this request into a download */ | |
@available(iOS 9.0, *) | |
case becomeStream = 3 /* Turn this task into a stream task */ | |
} | |
} | |
@available(iOS 7.0, *) | |
public protocol URLSessionDelegate : NSObjectProtocol { | |
optional func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) | |
optional func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) | |
optional func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge) async -> (URLSession.AuthChallengeDisposition, URLCredential?) | |
@available(iOS 7.0, *) | |
optional func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) | |
} | |
@available(iOS 7.0, *) | |
public protocol URLSessionTaskDelegate : URLSessionDelegate { | |
@available(iOS 16.0, *) | |
optional func urlSession(_ session: URLSession, didCreateTask task: URLSessionTask) | |
@available(iOS 11.0, *) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping @Sendable (URLSession.DelayedRequestDisposition, URLRequest?) -> Void) | |
@available(iOS 11.0, *) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest) async -> (URLSession.DelayedRequestDisposition, URLRequest?) | |
@available(iOS 11.0, *) | |
optional func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping @Sendable (URLRequest?) -> Void) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest) async -> URLRequest? | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge) async -> (URLSession.AuthChallengeDisposition, URLCredential?) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, needNewBodyStream completionHandler: @escaping @Sendable (InputStream?) -> Void) | |
optional func urlSession(_ session: URLSession, needNewBodyStreamForTask task: URLSessionTask) async -> InputStream? | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) | |
@available(iOS 10.0, *) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) | |
optional func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) | |
} | |
@available(iOS 7.0, *) | |
public protocol URLSessionDataDelegate : URLSessionTaskDelegate { | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping @Sendable (URLSession.ResponseDisposition) -> Void) | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse) async -> URLSession.ResponseDisposition | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didBecome downloadTask: URLSessionDownloadTask) | |
@available(iOS 9.0, *) | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didBecome streamTask: URLSessionStreamTask) | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse, completionHandler: @escaping @Sendable (CachedURLResponse?) -> Void) | |
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, willCacheResponse proposedResponse: CachedURLResponse) async -> CachedURLResponse? | |
} | |
@available(iOS 7.0, *) | |
public protocol URLSessionDownloadDelegate : URLSessionTaskDelegate { | |
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) | |
optional func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) | |
optional func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didResumeAtOffset fileOffset: Int64, expectedTotalBytes: Int64) | |
} | |
@available(iOS 9.0, *) | |
public protocol URLSessionStreamDelegate : URLSessionTaskDelegate { | |
optional func urlSession(_ session: URLSession, readClosedFor streamTask: URLSessionStreamTask) | |
optional func urlSession(_ session: URLSession, writeClosedFor streamTask: URLSessionStreamTask) | |
optional func urlSession(_ session: URLSession, betterRouteDiscoveredFor streamTask: URLSessionStreamTask) | |
optional func urlSession(_ session: URLSession, streamTask: URLSessionStreamTask, didBecome inputStream: InputStream, outputStream: OutputStream) | |
} | |
@available(iOS 13.0, *) | |
public protocol URLSessionWebSocketDelegate : URLSessionTaskDelegate { | |
optional func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) | |
optional func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) | |
} | |
/* Key in the userInfo dictionary of an NSError received during a failed download. */ | |
@available(iOS 7.0, *) | |
public let NSURLSessionDownloadTaskResumeData: String | |
extension URLSessionConfiguration { | |
@available(iOS, introduced: 7.0, deprecated: 8.0) | |
open class func backgroundSessionConfiguration(_ identifier: String) -> URLSessionConfiguration | |
} | |
extension URLSessionTaskMetrics { | |
@available(iOS 10.0, *) | |
public enum ResourceFetchType : Int, @unchecked Sendable { | |
case unknown = 0 | |
case networkLoad = 1 | |
case serverPush = 2 | |
case localCache = 3 | |
} | |
/* | |
* DNS protocol used for domain resolution. | |
*/ | |
@available(iOS 14.0, *) | |
public enum DomainResolutionProtocol : Int, @unchecked Sendable { | |
case unknown = 0 | |
case udp = 1 /* Resolution used DNS over UDP. */ | |
case tcp = 2 /* Resolution used DNS over TCP. */ | |
case tls = 3 /* Resolution used DNS over TLS. */ | |
case https = 4 /* Resolution used DNS over HTTPS. */ | |
} | |
} | |
@available(iOS 10.0, *) | |
open class URLSessionTaskTransactionMetrics : NSObject, @unchecked Sendable { | |
open var request: URLRequest { get } | |
@NSCopying open var response: URLResponse? { get } | |
open var fetchStartDate: Date? { get } | |
open var domainLookupStartDate: Date? { get } | |
open var domainLookupEndDate: Date? { get } | |
open var connectStartDate: Date? { get } | |
open var secureConnectionStartDate: Date? { get } | |
open var secureConnectionEndDate: Date? { get } | |
open var connectEndDate: Date? { get } | |
open var requestStartDate: Date? { get } | |
open var requestEndDate: Date? { get } | |
open var responseStartDate: Date? { get } | |
open var responseEndDate: Date? { get } | |
open var networkProtocolName: String? { get } | |
open var isProxyConnection: Bool { get } | |
open var isReusedConnection: Bool { get } | |
open var resourceFetchType: URLSessionTaskMetrics.ResourceFetchType { get } | |
@available(iOS 13.0, *) | |
open var countOfRequestHeaderBytesSent: Int64 { get } | |
@available(iOS 13.0, *) | |
open var countOfRequestBodyBytesSent: Int64 { get } | |
@available(iOS 13.0, *) | |
open var countOfRequestBodyBytesBeforeEncoding: Int64 { get } | |
@available(iOS 13.0, *) | |
open var countOfResponseHeaderBytesReceived: Int64 { get } | |
@available(iOS 13.0, *) | |
open var countOfResponseBodyBytesReceived: Int64 { get } | |
@available(iOS 13.0, *) | |
open var countOfResponseBodyBytesAfterDecoding: Int64 { get } | |
@available(iOS 13.0, *) | |
open var localAddress: String? { get } | |
@available(iOS 13.0, *) | |
open var remoteAddress: String? { get } | |
@available(iOS 13.0, *) | |
open var isCellular: Bool { get } | |
@available(iOS 13.0, *) | |
open var isExpensive: Bool { get } | |
@available(iOS 13.0, *) | |
open var isConstrained: Bool { get } | |
@available(iOS 13.0, *) | |
open var isMultipath: Bool { get } | |
@available(iOS 14.0, *) | |
open var domainResolutionProtocol: URLSessionTaskMetrics.DomainResolutionProtocol { get } | |
@available(iOS, introduced: 10.0, deprecated: 13.0, message: "Not supported") | |
public init() | |
@available(iOS, introduced: 10.0, deprecated: 13.0, message: "Not supported") | |
open class func new() -> Self | |
} | |
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | |
extension URLSessionTaskTransactionMetrics { | |
public var localPort: Int? { get } | |
public var remotePort: Int? { get } | |
public var negotiatedTLSProtocolVersion: tls_protocol_version_t? { get } | |
public var negotiatedTLSCipherSuite: tls_ciphersuite_t? { get } | |
} | |
@available(iOS 10.0, *) | |
open class URLSessionTaskMetrics : NSObject, @unchecked Sendable { | |
open var transactionMetrics: [URLSessionTaskTransactionMetrics] { get } | |
open var taskInterval: DateInterval { get } | |
open var redirectCount: Int { get } | |
@available(iOS, introduced: 10.0, deprecated: 13.0, message: "Not supported") | |
public init() | |
@available(iOS, introduced: 10.0, deprecated: 13.0, message: "Not supported") | |
open class func new() -> Self | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment