-
Notifications
You must be signed in to change notification settings - Fork 1
DownloadRequest
Request
subclass which downloads Data
to a file on disk using URLSessionDownloadTask
.
public class DownloadRequest: Request
Request
, CustomStringConvertible
, Equatable
, Hashable
- DownloadRequest.Options
- DownloadRequest.Downloadable
- DownloadRequest.DownloadRequestMutableState
- Request.MIMEType
A closure executed once a download request has successfully completed in order to determine where to move the temporary file written to during the download process. The closure takes two arguments: the temporary file URL and the URL response, and returns a two arguments: the file URL where the temporary file should be moved and the options defining how the file should be moved.
Typealias(context: Optional("DownloadRequest"), attributes: [], modifiers: [public], keyword: "typealias", name: "Destination", initializedType: Optional("(_ temporaryURL: URL,\n _ response: HTTPURLResponse) -> (destinationURL: URL, options: Options)"), genericParameters: [], genericRequirements: [])
A closure used to validate a request that takes a URL request, a URL response, a temporary URL and a destination URL, and returns whether the request was valid.
Typealias(context: Optional("DownloadRequest"), attributes: [], modifiers: [public], keyword: "typealias", name: "Validation", initializedType: Optional("(_ request: URLRequest?,\n _ response: HTTPURLResponse,\n _ fileURL: URL?)\n -> ValidationResult"), genericParameters: [], genericRequirements: [])
Used to represent whether a validation succeeded or failed.
Typealias(context: Optional("Request"), attributes: [], modifiers: [public], keyword: "typealias", name: "ValidationResult", initializedType: Optional("Result<Void, Error>"), genericParameters: [], genericRequirements: [])
If the download is resumable and eventually cancelled, this value may be used to resume the download using the
download(resumingWith data:)
API.
var resumeData: Data?
Note: For more information about
resumeData
, see Apple's documentation.
If the download is successful, the URL
where the file was downloaded.
var fileURL: URL?
Downloadable
value used for this instance.
let downloadable: Downloadable
A textual representation of this instance, including the HTTPMethod
and URL
if the URLRequest
has been
created, as well as the response status code, if a response has been received.
var description: String
Creates a download file destination closure which uses the default file manager to move the temporary file to a file URL in the first available directory with the specified search path directory and search path domain mask.
public class func suggestedDownloadDestination(for directory: FileManager.SearchPathDirectory = .documentDirectory, in domain: FileManager.SearchPathDomainMask = .userDomainMask, options: Options = []) -> Destination
- directory: The search path directory.
.documentDirectory
by default. - domain: The search path domain mask.
.userDomainMask
by default. - options:
DownloadRequest.Options
used when moving the downloaded file to its destination. None by default.
The Destination
closure.
Creates a URLSessionTask
from the provided resume data.
public func task(forResumeData data: Data, using session: URLSession) -> URLSessionTask
- data:
Data
used to resume the download. - session:
URLSession
used to create theURLSessionTask
.
The URLSessionTask
created.
Cancels the instance. Once cancelled, a DownloadRequest
can no longer be resumed or suspended.
@discardableResult public override func cancel() -> Self
Note: This method will NOT produce resume data. If you wish to cancel and produce resume data, use
cancel(producingResumeData:)
orcancel(byProducingResumeData:)
.
The instance.
Cancels the instance, optionally producing resume data. Once cancelled, a DownloadRequest
can no longer be
resumed or suspended.
@discardableResult public func cancel(producingResumeData shouldProduceResumeData: Bool) -> Self
Note: If
producingResumeData
istrue
, theresumeData
property will be populated with any resume data, if available.
The instance.
Cancels the instance while producing resume data. Once cancelled, a DownloadRequest
can no longer be resumed
or suspended.
@discardableResult public func cancel(byProducingResumeData completionHandler: @escaping (_ data: Data?) -> Void) -> Self
Note: The resume data passed to the completion handler will also be available on the instance's
resumeData
property.
- Parameter completionHandler: The completion handler that is called when the download has been successfully cancelled. It is not guaranteed to be called on a particular queue, so you may want use an appropriate queue to perform your work.
The instance.
Validates the request, using the specified closure.
@discardableResult public func validate(_ validation: @escaping Validation) -> Self
Note: If validation fails, subsequent calls to response handlers will have an associated error.
- Parameter validation:
Validation
closure to validate the response.
The instance.
Adds a handler to be called once the request has finished.
@discardableResult public func response(queue: DispatchQueue = .main, completionHandler: @escaping (AFDownloadResponse<URL?>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - completionHandler: The code to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func response<T: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main, responseSerializer: T, completionHandler: @escaping (AFDownloadResponse<T.SerializedObject>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - responseSerializer: The response serializer responsible for serializing the request, response, and data contained in the destination
URL
. - completionHandler: The code to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseData(queue: DispatchQueue = .main, completionHandler: @escaping (AFDownloadResponse<Data>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - completionHandler: The code to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseString(queue: DispatchQueue = .main, encoding: String.Encoding? = nil, completionHandler: @escaping (AFDownloadResponse<String>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - encoding: The string encoding. Defaults to
nil
, in which case the encoding will be determined from the server response, falling back to the default HTTP character set,ISO-8859-1
. - completionHandler: A closure to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (AFDownloadResponse<Any>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - options: The JSON serialization reading options.
.allowFragments
by default. - completionHandler: A closure to be executed once the request has finished.
The request.
Validates that the response has a status code in the specified sequence.
@discardableResult public func validate<S: Sequence>(statusCode acceptableStatusCodes: S) -> Self where S.Iterator.Element == Int
If validation fails, subsequent calls to response handlers will have an associated error.
- parameter range: The range of acceptable status codes.
The request.
Validates that the response has a content type in the specified sequence.
@discardableResult public func validate<S: Sequence>(contentType acceptableContentTypes: @escaping @autoclosure () -> S) -> Self where S.Iterator.Element == String
If validation fails, subsequent calls to response handlers will have an associated error.
- parameter contentType: The acceptable content types, which may specify wildcard types and/or subtypes.
The request.
Validates that the response has a status code in the default acceptable range of 200...299, and that the content type matches any specified in the Accept HTTP header field.
@discardableResult public func validate() -> Self
If validation fails, subsequent calls to response handlers will have an associated error.
The request.
public static func ==(lhs: Request, rhs: Request) -> Bool
public func hash(into hasher: inout Hasher)
cURL representation of the instance.
public func cURLDescription() -> String
The cURL equivalent of the instance.
Generated at 2020-09-24T22:11:06+0000 using swift-doc 1.0.0-beta.4.
Types
- AF
- AFError
- AFError.MultipartEncodingFailureReason
- AFError.ParameterEncoderFailureReason
- AFError.ParameterEncoderFailureReason.RequiredComponent
- AFError.ParameterEncodingFailureReason
- AFError.ResponseSerializationFailureReason
- AFError.ResponseValidationFailureReason
- AFError.ServerTrustFailureReason
- AFError.ServerTrustFailureReason.Output
- AFError.URLRequestValidationFailureReason
- Adapter
- AlamofireExtension
- AlamofireNotifications
- ClosureEventMonitor
- CompositeEventMonitor
- CompositeTrustEvaluator
- ConnectionLostRetryPolicy
- DataRequest
- DataResponse
- DataResponseSerializer
- DecodableResponseSerializer
- DefaultTrustEvaluator
- DisabledEvaluator
- DownloadRequest
- DownloadRequest.Downloadable
- DownloadRequest.Options
- DownloadResponse
- Empty
- GoogleXSSIPreprocessor
- HTTPHeader
- HTTPHeaders
- HTTPMethod
- Interceptor
- JSONEncoding
- JSONParameterEncoder
- JSONResponseSerializer
- MultipartFormData
- NetworkReachabilityManager
- NetworkReachabilityManager.NetworkReachabilityStatus
- NetworkReachabilityManager.NetworkReachabilityStatus.ConnectionType
- PassthroughPreprocessor
- PinnedCertificatesTrustEvaluator
- PublicKeysTrustEvaluator
- Redirector
- Redirector.Behavior
- Request
- Request.State
- ResponseCacher
- ResponseCacher.Behavior
- Retrier
- RetryPolicy
- RetryResult
- RevocationTrustEvaluator
- RevocationTrustEvaluator.Options
- ServerTrustManager
- Session
- SessionDelegate
- StringResponseSerializer
- URLEncodedFormEncoder
- URLEncodedFormEncoder.ArrayEncoding
- URLEncodedFormEncoder.BoolEncoding
- URLEncodedFormEncoder.DataEncoding
- URLEncodedFormEncoder.DateEncoding
- URLEncodedFormEncoder.Error
- URLEncodedFormEncoder.KeyEncoding
- URLEncodedFormEncoder.SpaceEncoding
- URLEncodedFormParameterEncoder
- URLEncodedFormParameterEncoder.Destination
- URLEncoding
- URLEncoding.ArrayEncoding
- URLEncoding.BoolEncoding
- URLEncoding.Destination
- UploadRequest
- UploadRequest.Uploadable
Protocols
- AlamofireExtended
- CachedResponseHandler
- DataDecoder
- DataPreprocessor
- DataResponseSerializerProtocol
- DownloadResponseSerializerProtocol
- EmptyResponse
- EventMonitor
- ParameterEncoder
- ParameterEncoding
- RedirectHandler
- RequestAdapter
- RequestDelegate
- RequestInterceptor
- RequestRetrier
- ResponseSerializer
- ServerTrustEvaluating
- URLConvertible
- URLRequestConvertible
- UploadConvertible
- UploadableConvertible