FWURLSessionManager
@interface FWURLSessionManager
: NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate,
NSURLSessionDataDelegate, NSURLSessionDownloadDelegate,
NSSecureCoding, NSCopying>
FWURLSessionManager creates and manages an NSURLSession object based on a specified NSURLSessionConfiguration object, which conforms to <NSURLSessionTaskDelegate>, <NSURLSessionDataDelegate>, <NSURLSessionDownloadDelegate>, and <NSURLSessionDelegate>.
Subclassing Notes
This is the base class for FWHTTPSessionManager, which adds functionality specific to making HTTP requests. If you are looking to extend FWURLSessionManager specifically for HTTP, consider subclassing FWHTTPSessionManager instead.
NSURLSession & NSURLSessionTask Delegate Methods
FWURLSessionManager implements the following delegate methods:
NSURLSessionDelegate
URLSession:didBecomeInvalidWithError:URLSession:didReceiveChallenge:completionHandler:URLSessionDidFinishEventsForBackgroundURLSession:
NSURLSessionTaskDelegate
URLSession:willPerformHTTPRedirection:newRequest:completionHandler:URLSession:task:didReceiveChallenge:completionHandler:URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:URLSession:task:needNewBodyStream:URLSession:task:didCompleteWithError:
NSURLSessionDataDelegate
URLSession:dataTask:didReceiveResponse:completionHandler:URLSession:dataTask:didBecomeDownloadTask:URLSession:dataTask:didReceiveData:URLSession:dataTask:willCacheResponse:completionHandler:
NSURLSessionDownloadDelegate
URLSession:downloadTask:didFinishDownloadingToURL:URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:URLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:
If any of these methods are overridden in a subclass, they must call the super implementation first.
Network Reachability Monitoring
Network reachability status and change monitoring is available through the reachabilityManager property. Applications may choose to monitor network reachability conditions in order to prevent or suspend any outbound requests. See FWNetworkReachabilityManager for more details.
NSCoding Caveats
- Encoded managers do not include any block properties. Be sure to set delegate callback blocks when using
-initWithCoder:orNSKeyedUnarchiver.
NSCopying Caveats
-copyand-copyWithZone:return a new manager with a newNSURLSessioncreated from the configuration of the original.Operation copies do not include any delegate callback blocks, as they often strongly captures a reference to
self, which would otherwise have the unintuitive side-effect of pointing to the original session manager when copied.
Warning
Managers for background sessions must be owned for the duration of their use. This can be accomplished by creating an application-wide or shared singleton instance.
-
The managed session.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSURLSession *_Nonnull session; -
The operation queue on which delegate callbacks are run.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSOperationQueue *_Nonnull operationQueue; -
Responses sent from the server in data tasks created with
dataTaskWithRequest:success:failure:and run using theGET/POST/ et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance ofFWJSONResponseSerializer.Warning
responseSerializermust not benil.Declaration
Objective-C
@property (nonatomic, strong) id<FWURLResponseSerialization> _Nonnull responseSerializer;
-
The security policy used by created session to evaluate server trust for secure connections.
FWURLSessionManageruses thedefaultPolicyunless otherwise specified.Declaration
Objective-C
@property (nonatomic, strong) FWSecurityPolicy *_Nonnull securityPolicy;
-
The network reachability manager.
FWURLSessionManageruses thesharedManagerby default.Declaration
Objective-C
@property (nonatomic, strong) FWNetworkReachabilityManager *_Nonnull reachabilityManager;
-
The data, upload, and download tasks currently run by the managed session.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSArray<NSURLSessionTask *> *_Nonnull tasks; -
The data tasks currently run by the managed session.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSArray<NSURLSessionDataTask *> *_Nonnull dataTasks; -
The upload tasks currently run by the managed session.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSArray<NSURLSessionUploadTask *> *_Nonnull uploadTasks; -
The download tasks currently run by the managed session.
Declaration
Objective-C
@property (nonatomic, strong, readonly) NSArray<NSURLSessionDownloadTask *> *_Nonnull downloadTasks;
-
The dispatch queue for
completionBlock. IfNULL(default), the main queue is used.Declaration
Objective-C
@property (nonatomic, strong, nullable) dispatch_queue_t completionQueue; -
The dispatch group for
completionBlock. IfNULL(default), a private dispatch group is used.Declaration
Objective-C
@property (nonatomic, strong, nullable) dispatch_group_t completionGroup;
-
Creates and returns a manager for a session created with the specified configuration. This is the designated initializer.
Declaration
Objective-C
- (nonnull instancetype)initWithSessionConfiguration: (nullable NSURLSessionConfiguration *)configuration;Parameters
configurationThe configuration used to create the managed session.
Return Value
A manager for a newly-created session.
-
Invalidates the managed session, optionally canceling pending tasks and optionally resets given session.
Declaration
Objective-C
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks resetSession:(BOOL)resetSession;Parameters
cancelPendingTasksWhether or not to cancel pending tasks.
resetSessionWhether or not to reset the session of the manager.
-
Creates an
NSURLSessionDataTaskwith the specified request.Declaration
Objective-C
- (nonnull NSURLSessionDataTask *) dataTaskWithRequest:(nonnull NSURLRequest *)request uploadProgress:(nullable void (^)(NSProgress *_Nonnull __strong)) uploadProgressBlock downloadProgress:(nullable void (^)(NSProgress *_Nonnull __strong)) downloadProgressBlock completionHandler: (nullable void (^)(NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestThe HTTP request for the request.
uploadProgressBlockA block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
downloadProgressBlockA block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
completionHandlerA block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
-
-dataTaskWithRequestBuilder:retryCount: retryInterval: timeoutInterval: shouldRetry: taskHandler: uploadProgress: downloadProgress: completionHandler: Creates an
NSURLSessionDataTaskwith a retry request.See
-dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
Declaration
Objective-C
- (nonnull NSURLSessionDataTask *) dataTaskWithRequestBuilder: (nonnull NSURLRequest *_Nonnull (^)(void))requestBuilder retryCount:(NSInteger)retryCount retryInterval:(NSTimeInterval)retryInterval timeoutInterval:(NSTimeInterval)timeoutInterval shouldRetry:(nullable void (^)( NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong, void (^_Nonnull __strong)(BOOL)))shouldRetry taskHandler: (nullable void (^)( NSURLSessionDataTask *_Nonnull __strong))taskHandler uploadProgress:(nullable void (^)( NSProgress *_Nonnull __strong))uploadProgress downloadProgress: (nullable void (^)(NSProgress *_Nonnull __strong)) downloadProgress completionHandler: (nullable void (^)( NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestBuilderThe request builder.
retryCountThe retry limit, eg 4.
retryIntervalThe retry interval, eg 2.
timeoutIntervalThe retry timeout, 0 means no timeout.
shouldRetryWhether the retry should start, must call decisionHandler, default to check statusCode and error.
taskHandlerA block object to be executed when the retry task is created.
uploadProgressA block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
downloadProgressA block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
completionHandlerA block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
-
Creates an
NSURLSessionUploadTaskwith the specified request for a local file.See
attemptsToRecreateUploadTasksForBackgroundSessionsDeclaration
Objective-C
- (nonnull NSURLSessionUploadTask *) uploadTaskWithRequest:(nonnull NSURLRequest *)request fromFile:(nonnull NSURL *)fileURL progress:(nullable void (^)(NSProgress *_Nonnull __strong)) uploadProgressBlock completionHandler: (nullable void (^)(NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestThe HTTP request for the request.
fileURLA URL to the local file to be uploaded.
uploadProgressBlockA block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
completionHandlerA block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
-
Creates an
NSURLSessionUploadTaskwith the specified request for an HTTP body.Declaration
Objective-C
- (nonnull NSURLSessionUploadTask *) uploadTaskWithRequest:(nonnull NSURLRequest *)request fromData:(nullable NSData *)bodyData progress:(nullable void (^)(NSProgress *_Nonnull __strong)) uploadProgressBlock completionHandler: (nullable void (^)(NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestThe HTTP request for the request.
bodyDataA data object containing the HTTP body to be uploaded.
uploadProgressBlockA block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
completionHandlerA block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
-
Creates an
NSURLSessionUploadTaskwith the specified streaming request.Declaration
Objective-C
- (nonnull NSURLSessionUploadTask *) uploadTaskWithStreamedRequest:(nonnull NSURLRequest *)request progress: (nullable void (^)(NSProgress *_Nonnull __strong)) uploadProgressBlock completionHandler: (nullable void (^)( NSURLResponse *_Nonnull __strong, id _Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestThe HTTP request for the request.
uploadProgressBlockA block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
completionHandlerA block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
-
Creates an
NSURLSessionDownloadTaskwith the specified request.Warning
If using a background
NSURLSessionConfigurationon iOS, these blocks will be lost when the app is terminated. Background sessions may prefer to use-setDownloadTaskDidFinishDownloadingBlock:to specify the URL for saving the downloaded file, rather than the destination block of this method.Declaration
Objective-C
- (nonnull NSURLSessionDownloadTask *) downloadTaskWithRequest:(nonnull NSURLRequest *)request progress:(nullable void (^)(NSProgress *_Nonnull __strong)) downloadProgressBlock destination:(nullable NSURL *_Nonnull (^)( NSURL *_Nonnull __strong, NSURLResponse *_Nonnull __strong))destination completionHandler: (nullable void (^)(NSURLResponse *_Nonnull __strong, NSURL *_Nullable __strong, NSError *_Nullable __strong))completionHandler;Parameters
requestThe HTTP request for the request.
downloadProgressBlockA block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
destinationA block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL.
completionHandlerA block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any.
-
Creates an
NSURLSessionDownloadTaskwith the specified resume data.Declaration
Objective-C
- (nonnull NSURLSessionDownloadTask *) downloadTaskWithResumeData:(nonnull NSData *)resumeData progress: (nullable void (^)(NSProgress *_Nonnull __strong)) downloadProgressBlock destination:(nullable NSURL *_Nonnull (^)( NSURL *_Nonnull __strong, NSURLResponse *_Nonnull __strong))destination completionHandler: (nullable void (^)(NSURLResponse *_Nonnull __strong, NSURL *_Nullable __strong, NSError *_Nullable __strong)) completionHandler;Parameters
resumeDataThe data used to resume downloading.
downloadProgressBlockA block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
destinationA block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL.
completionHandlerA block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any.
-
Returns the upload progress of the specified task.
Declaration
Objective-C
- (nullable NSProgress *)uploadProgressForTask:(nonnull NSURLSessionTask *)task;Parameters
taskThe session task. Must not be
nil.Return Value
An
NSProgressobject reporting the upload progress of a task, ornilif the progress is unavailable. -
Returns the download progress of the specified task.
Declaration
Objective-C
- (nullable NSProgress *)downloadProgressForTask: (nonnull NSURLSessionTask *)task;Parameters
taskThe session task. Must not be
nil.Return Value
An
NSProgressobject reporting the download progress of a task, ornilif the progress is unavailable. -
Sets a user info to be used for the specified task.
Declaration
Objective-C
- (void)setUserInfo:(nullable NSDictionary *)userInfo forTask:(nonnull NSURLSessionTask *)task; -
Returns the user info of the specified task.
Declaration
Objective-C
- (nullable NSDictionary *)userInfoForTask:(nonnull NSURLSessionTask *)task; -
Sets total request count to be used for the specified response.
Declaration
Objective-C
- (void)setRequestTotalCount:(NSInteger)totalCount forResponse:(nonnull NSURLResponse *)response; -
Returns the total request count of the specified response.
Declaration
Objective-C
- (NSInteger)requestTotalCountForResponse:(nonnull NSURLResponse *)response; -
Sets total request time to be used for the specified response.
Declaration
Objective-C
- (void)setRequestTotalTime:(NSTimeInterval)totalTime forResponse:(nonnull NSURLResponse *)response; -
Returns the retry total request time of the specified response.
Declaration
Objective-C
- (NSTimeInterval)requestTotalTimeForResponse:(nonnull NSURLResponse *)response;
-
Sets a block to be executed when the managed session becomes invalid, as handled by the
NSURLSessionDelegatemethodURLSession:didBecomeInvalidWithError:.Declaration
Objective-C
- (void)setSessionDidBecomeInvalidBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSError *_Nonnull __strong))block;Parameters
blockA block object to be executed when the managed session becomes invalid. The block has no return value, and takes two arguments: the session, and the error related to the cause of invalidation.
-
Sets a block to be executed when a connection level authentication challenge has occurred, as handled by the
NSURLSessionDelegatemethodURLSession:didReceiveChallenge:completionHandler:.Warning
Implementing a session authentication challenge handler yourself totally bypasses FWNetworking’s security policy defined in
FWSecurityPolicy. Make sure you fully understand the implications before implementing a custom session authentication challenge handler. If you do not want to bypass FWNetworking’s security policy, use-setAuthenticationChallengeHandler:instead.See
-securityPolicy
See
-setAuthenticationChallengeHandler:
Declaration
Objective-C
- (void)setSessionDidReceiveAuthenticationChallengeBlock: (nullable NSURLSessionAuthChallengeDisposition (^)( NSURLSession *_Nonnull __strong, NSURLAuthenticationChallenge *_Nonnull __strong, NSURLCredential *__autoreleasing _Nullable *_Nullable))block;Parameters
blockA block object to be executed when a connection level authentication challenge has occurred. The block returns the disposition of the authentication challenge, and takes three arguments: the session, the authentication challenge, and a pointer to the credential that should be used to resolve the challenge.
-
Sets a block to be executed when a task requires a new request body stream to send to the remote server, as handled by the
NSURLSessionTaskDelegatemethodURLSession:task:needNewBodyStream:.Declaration
Objective-C
- (void)setTaskNeedNewBodyStreamBlock: (nullable NSInputStream *_Nonnull (^)(NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong)) block;Parameters
blockA block object to be executed when a task requires a new request body stream.
-
Sets a block to be executed when an HTTP request is attempting to perform a redirection to a different URL, as handled by the
NSURLSessionTaskDelegatemethodURLSession:willPerformHTTPRedirection:newRequest:completionHandler:.Declaration
Objective-C
- (void)setTaskWillPerformHTTPRedirectionBlock: (nullable NSURLRequest *_Nullable (^)( NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong, NSURLResponse *_Nonnull __strong, NSURLRequest *_Nonnull __strong))block;Parameters
blockA block object to be executed when an HTTP request is attempting to perform a redirection to a different URL. The block returns the request to be made for the redirection, and takes four arguments: the session, the task, the redirection response, and the request corresponding to the redirection response.
-
Sets a block to be executed when a session task has received a request specific authentication challenge, as handled by the
NSURLSessionTaskDelegatemethodURLSession:task:didReceiveChallenge:completionHandler:.When implementing an authentication challenge handler, you should check the authentication method first (
challenge.protectionSpace.authenticationMethod) to decide if you want to handle the authentication challenge yourself or if you want FWNetworking to handle it. If you want FWNetworking to handle the authentication challenge, just return@(NSURLSessionAuthChallengePerformDefaultHandling). For example, you certainly want FWNetworking to handle certificate validation (i.e. authentication method ==NSURLAuthenticationMethodServerTrust) as defined by the security policy. If you want to handle the challenge yourself, you have four options:- Return
nilfrom the authentication challenge handler. You MUST call the completion handler with a disposition and credentials yourself. Use this if you need to present a user interface to let the user enter their credentials. - Return an
NSErrorobject from the authentication challenge handler. You MUST NOT call the completion handler when returning anNSError. The returned error will be reported in the completion handler of the task. Use this if you need to abort an authentication challenge with a specific error. - Return an
NSURLCredentialobject from the authentication challenge handler. You MUST NOT call the completion handler when returning anNSURLCredential. The returned credentials will be used to fulfil the challenge. Use this when you can get credentials without presenting a user interface. - Return an
NSNumberobject wrapping anNSURLSessionAuthChallengeDisposition. Supported values are@(NSURLSessionAuthChallengePerformDefaultHandling),@(NSURLSessionAuthChallengeCancelAuthenticationChallenge)and@(NSURLSessionAuthChallengeRejectProtectionSpace). You MUST NOT call the completion handler when returning anNSNumber.
If you return anything else from the authentication challenge handler, an exception will be thrown.
For more information about how URL sessions handle the different types of authentication challenges, see NSURLSession and URL Session Programming Guide.
See
-securityPolicyDeclaration
Objective-C
- (void)setAuthenticationChallengeHandler: (nonnull id _Nonnull (^)( NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong, NSURLAuthenticationChallenge *_Nonnull __strong, void (^_Nonnull __strong)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable __strong))) authenticationChallengeHandler;Parameters
authenticationChallengeHandlerA block object to be executed when a session task has received a request specific authentication challenge.
- Return
-
Sets a block to be executed periodically to track upload progress, as handled by the
NSURLSessionTaskDelegatemethodURLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:.Declaration
Objective-C
- (void)setTaskDidSendBodyDataBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong, int64_t, int64_t, int64_t))block;Parameters
blockA block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes five arguments: the session, the task, the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread.
-
Sets a block to be executed as the last message related to a specific task, as handled by the
NSURLSessionTaskDelegatemethodURLSession:task:didCompleteWithError:.Declaration
Objective-C
- (void)setTaskDidCompleteBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong, NSError *_Nullable __strong))block;Parameters
blockA block object to be executed when a session task is completed. The block has no return value, and takes three arguments: the session, the task, and any error that occurred in the process of executing the task.
-
Sets a block to be executed when metrics are finalized related to a specific task, as handled by the
NSURLSessionTaskDelegatemethodURLSession:task:didFinishCollectingMetrics:.Declaration
Objective-C
- (void)setTaskDidFinishCollectingMetricsBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionTask *_Nonnull __strong, NSURLSessionTaskMetrics *_Nullable __strong))block;Parameters
blockA block object to be executed when a session task is completed. The block has no return value, and takes three arguments: the session, the task, and any metrics that were collected in the process of executing the task.
-
Sets a block to be executed when a data task has received a response, as handled by the
NSURLSessionDataDelegatemethodURLSession:dataTask:didReceiveResponse:completionHandler:.Declaration
Objective-C
- (void)setDataTaskDidReceiveResponseBlock: (nullable NSURLSessionResponseDisposition (^)( NSURLSession *_Nonnull __strong, NSURLSessionDataTask *_Nonnull __strong, NSURLResponse *_Nonnull __strong))block;Parameters
blockA block object to be executed when a data task has received a response. The block returns the disposition of the session response, and takes three arguments: the session, the data task, and the received response.
-
Sets a block to be executed when a data task has become a download task, as handled by the
NSURLSessionDataDelegatemethodURLSession:dataTask:didBecomeDownloadTask:.Declaration
Objective-C
- (void)setDataTaskDidBecomeDownloadTaskBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionDataTask *_Nonnull __strong, NSURLSessionDownloadTask *_Nonnull __strong))block;Parameters
blockA block object to be executed when a data task has become a download task. The block has no return value, and takes three arguments: the session, the data task, and the download task it has become.
-
Sets a block to be executed when a data task receives data, as handled by the
NSURLSessionDataDelegatemethodURLSession:dataTask:didReceiveData:.Declaration
Objective-C
- (void)setDataTaskDidReceiveDataBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionDataTask *_Nonnull __strong, NSData *_Nonnull __strong))block;Parameters
blockA block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the session, the data task, and the data received. This block may be called multiple times, and will execute on the session manager operation queue.
-
Sets a block to be executed to determine the caching behavior of a data task, as handled by the
NSURLSessionDataDelegatemethodURLSession:dataTask:willCacheResponse:completionHandler:.Declaration
Objective-C
- (void)setDataTaskWillCacheResponseBlock: (nullable NSCachedURLResponse *_Nonnull (^)( NSURLSession *_Nonnull __strong, NSURLSessionDataTask *_Nonnull __strong, NSCachedURLResponse *_Nonnull __strong))block;Parameters
blockA block object to be executed to determine the caching behavior of a data task. The block returns the response to cache, and takes three arguments: the session, the data task, and the proposed cached URL response.
-
Sets a block to be executed once all messages enqueued for a session have been delivered, as handled by the
NSURLSessionDataDelegatemethodURLSessionDidFinishEventsForBackgroundURLSession:.Declaration
Objective-C
- (void)setDidFinishEventsForBackgroundURLSessionBlock: (nullable void (^)(NSURLSession *_Nonnull __strong))block;Parameters
blockA block object to be executed once all messages enqueued for a session have been delivered. The block has no return value and takes a single argument: the session.
-
Sets a block to be executed when a download task has completed a download, as handled by the
NSURLSessionDownloadDelegatemethodURLSession:downloadTask:didFinishDownloadingToURL:.Declaration
Objective-C
- (void)setDownloadTaskDidFinishDownloadingBlock: (nullable NSURL *_Nullable (^)(NSURLSession *_Nonnull __strong, NSURLSessionDownloadTask *_Nonnull __strong, NSURL *_Nonnull __strong))block;Parameters
blockA block object to be executed when a download task has completed. The block returns the URL the download should be moved to, and takes three arguments: the session, the download task, and the temporary location of the downloaded file. If the file manager encounters an error while attempting to move the temporary file to the destination, an
FWURLSessionDownloadTaskDidFailToMoveFileNotificationwill be posted, with the download task as its object, and the user info of the error. -
Sets a block to be executed periodically to track download progress, as handled by the
NSURLSessionDownloadDelegatemethodURLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:.Declaration
Objective-C
- (void)setDownloadTaskDidWriteDataBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionDownloadTask *_Nonnull __strong, int64_t, int64_t, int64_t))block;Parameters
blockA block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes five arguments: the session, the download task, the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the
NSHTTPURLResponseobject. This block may be called multiple times, and will execute on the session manager operation queue. -
Sets a block to be executed when a download task has been resumed, as handled by the
NSURLSessionDownloadDelegatemethodURLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:.Declaration
Objective-C
- (void)setDownloadTaskDidResumeBlock: (nullable void (^)(NSURLSession *_Nonnull __strong, NSURLSessionDownloadTask *_Nonnull __strong, int64_t, int64_t))block;Parameters
blockA block object to be executed when a download task has been resumed. The block has no return value and takes four arguments: the session, the download task, the file offset of the resumed download, and the total number of bytes expected to be downloaded.
FWURLSessionManager Class Reference