|
@@ -89,6 +89,8 @@
|
|
|
@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.
|
|
|
*/
|
|
|
|
|
|
+NS_ASSUME_NONNULL_BEGIN
|
|
|
+
|
|
|
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
|
|
|
|
|
|
@interface AFURLSessionManager : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NSSecureCoding, NSCopying>
|
|
@@ -160,18 +162,18 @@
|
|
|
The dispatch queue for `completionBlock`. If `NULL` (default), the main queue is used.
|
|
|
*/
|
|
|
#if OS_OBJECT_HAVE_OBJC_SUPPORT
|
|
|
-@property (nonatomic, strong) dispatch_queue_t completionQueue;
|
|
|
+@property (nonatomic, strong, nullable) dispatch_queue_t completionQueue;
|
|
|
#else
|
|
|
-@property (nonatomic, assign) dispatch_queue_t completionQueue;
|
|
|
+@property (nonatomic, assign, nullable) dispatch_queue_t completionQueue;
|
|
|
#endif
|
|
|
|
|
|
/**
|
|
|
The dispatch group for `completionBlock`. If `NULL` (default), a private dispatch group is used.
|
|
|
*/
|
|
|
#if OS_OBJECT_HAVE_OBJC_SUPPORT
|
|
|
-@property (nonatomic, strong) dispatch_group_t completionGroup;
|
|
|
+@property (nonatomic, strong, nullable) dispatch_group_t completionGroup;
|
|
|
#else
|
|
|
-@property (nonatomic, assign) dispatch_group_t completionGroup;
|
|
|
+@property (nonatomic, assign, nullable) dispatch_group_t completionGroup;
|
|
|
#endif
|
|
|
|
|
|
///---------------------------------
|
|
@@ -198,7 +200,7 @@
|
|
|
|
|
|
@return A manager for a newly-created session.
|
|
|
*/
|
|
|
-- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
|
|
|
+- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
|
|
|
|
|
|
/**
|
|
|
Invalidates the managed session, optionally canceling pending tasks.
|
|
@@ -218,7 +220,7 @@
|
|
|
@param completionHandler A 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.
|
|
|
*/
|
|
|
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
|
|
|
///---------------------------
|
|
|
/// @name Running Upload Tasks
|
|
@@ -236,8 +238,8 @@
|
|
|
*/
|
|
|
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
|
|
|
fromFile:(NSURL *)fileURL
|
|
|
- progress:(NSProgress * __autoreleasing *)progress
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
+ progress:(NSProgress * __nullable __autoreleasing * __nullable)progress
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
|
|
|
/**
|
|
|
Creates an `NSURLSessionUploadTask` with the specified request for an HTTP body.
|
|
@@ -248,9 +250,9 @@
|
|
|
@param completionHandler A 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.
|
|
|
*/
|
|
|
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
|
|
|
- fromData:(NSData *)bodyData
|
|
|
- progress:(NSProgress * __autoreleasing *)progress
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
+ fromData:(nullable NSData *)bodyData
|
|
|
+ progress:(NSProgress * __nullable __autoreleasing * __nullable)progress
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
|
|
|
/**
|
|
|
Creates an `NSURLSessionUploadTask` with the specified streaming request.
|
|
@@ -260,8 +262,8 @@
|
|
|
@param completionHandler A 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.
|
|
|
*/
|
|
|
- (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request
|
|
|
- progress:(NSProgress * __autoreleasing *)progress
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
+ progress:(NSProgress * __nullable __autoreleasing * __nullable)progress
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
|
|
|
|
|
|
///-----------------------------
|
|
|
/// @name Running Download Tasks
|
|
@@ -278,9 +280,9 @@
|
|
|
@warning If using a background `NSURLSessionConfiguration` on 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.
|
|
|
*/
|
|
|
- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
|
|
|
- progress:(NSProgress * __autoreleasing *)progress
|
|
|
- destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
|
|
|
+ progress:(NSProgress * __nullable __autoreleasing * __nullable)progress
|
|
|
+ destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
|
|
|
|
|
|
/**
|
|
|
Creates an `NSURLSessionDownloadTask` with the specified resume data.
|
|
@@ -291,9 +293,9 @@
|
|
|
@param completionHandler A 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.
|
|
|
*/
|
|
|
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData
|
|
|
- progress:(NSProgress * __autoreleasing *)progress
|
|
|
- destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
|
|
|
- completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
|
|
|
+ progress:(NSProgress * __nullable __autoreleasing * __nullable)progress
|
|
|
+ destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
|
|
|
+ completionHandler:(nullable void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
|
|
|
|
|
|
///---------------------------------
|
|
|
/// @name Getting Progress for Tasks
|
|
@@ -306,7 +308,7 @@
|
|
|
|
|
|
@return An `NSProgress` object reporting the upload progress of a task, or `nil` if the progress is unavailable.
|
|
|
*/
|
|
|
-- (NSProgress *)uploadProgressForTask:(NSURLSessionUploadTask *)uploadTask;
|
|
|
+- (nullable NSProgress *)uploadProgressForTask:(NSURLSessionUploadTask *)uploadTask;
|
|
|
|
|
|
/**
|
|
|
Returns the download progress of the specified task.
|
|
@@ -315,7 +317,7 @@
|
|
|
|
|
|
@return An `NSProgress` object reporting the download progress of a task, or `nil` if the progress is unavailable.
|
|
|
*/
|
|
|
-- (NSProgress *)downloadProgressForTask:(NSURLSessionDownloadTask *)downloadTask;
|
|
|
+- (nullable NSProgress *)downloadProgressForTask:(NSURLSessionDownloadTask *)downloadTask;
|
|
|
|
|
|
///-----------------------------------------
|
|
|
/// @name Setting Session Delegate Callbacks
|
|
@@ -326,14 +328,14 @@
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setSessionDidBecomeInvalidBlock:(void (^)(NSURLSession *session, NSError *error))block;
|
|
|
+- (void)setSessionDidBecomeInvalidBlock:(nullable void (^)(NSURLSession *session, NSError *error))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when a connection level authentication challenge has occurred, as handled by the `NSURLSessionDelegate` method `URLSession:didReceiveChallenge:completionHandler:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setSessionDidReceiveAuthenticationChallengeBlock:(NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential))block;
|
|
|
+- (void)setSessionDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __nullable __autoreleasing * __nullable credential))block;
|
|
|
|
|
|
///--------------------------------------
|
|
|
/// @name Setting Task Delegate Callbacks
|
|
@@ -344,35 +346,35 @@
|
|
|
|
|
|
@param block A block object to be executed when a task requires a new request body stream.
|
|
|
*/
|
|
|
-- (void)setTaskNeedNewBodyStreamBlock:(NSInputStream * (^)(NSURLSession *session, NSURLSessionTask *task))block;
|
|
|
+- (void)setTaskNeedNewBodyStreamBlock:(nullable NSInputStream * (^)(NSURLSession *session, NSURLSessionTask *task))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when an HTTP request is attempting to perform a redirection to a different URL, as handled by the `NSURLSessionTaskDelegate` method `URLSession:willPerformHTTPRedirection:newRequest:completionHandler:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setTaskWillPerformHTTPRedirectionBlock:(NSURLRequest * (^)(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request))block;
|
|
|
+- (void)setTaskWillPerformHTTPRedirectionBlock:(nullable NSURLRequest * (^)(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when a session task has received a request specific authentication challenge, as handled by the `NSURLSessionTaskDelegate` method `URLSession:task:didReceiveChallenge:completionHandler:`.
|
|
|
|
|
|
@param block A block object to be executed when a session task has received a request specific authentication challenge. The block returns the disposition of the authentication challenge, and takes four arguments: the session, the task, the authentication challenge, and a pointer to the credential that should be used to resolve the challenge.
|
|
|
*/
|
|
|
-- (void)setTaskDidReceiveAuthenticationChallengeBlock:(NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLSessionTask *task, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential))block;
|
|
|
+- (void)setTaskDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLSessionTask *task, NSURLAuthenticationChallenge *challenge, NSURLCredential * __nullable __autoreleasing * __nullable credential))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed periodically to track upload progress, as handled by the `NSURLSessionTaskDelegate` method `URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setTaskDidSendBodyDataBlock:(void (^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))block;
|
|
|
+- (void)setTaskDidSendBodyDataBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed as the last message related to a specific task, as handled by the `NSURLSessionTaskDelegate` method `URLSession:task:didCompleteWithError:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setTaskDidCompleteBlock:(void (^)(NSURLSession *session, NSURLSessionTask *task, NSError *error))block;
|
|
|
+- (void)setTaskDidCompleteBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSError *error))block;
|
|
|
|
|
|
///-------------------------------------------
|
|
|
/// @name Setting Data Task Delegate Callbacks
|
|
@@ -383,35 +385,35 @@
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDataTaskDidReceiveResponseBlock:(NSURLSessionResponseDisposition (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLResponse *response))block;
|
|
|
+- (void)setDataTaskDidReceiveResponseBlock:(nullable NSURLSessionResponseDisposition (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLResponse *response))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when a data task has become a download task, as handled by the `NSURLSessionDataDelegate` method `URLSession:dataTask:didBecomeDownloadTask:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDataTaskDidBecomeDownloadTaskBlock:(void (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLSessionDownloadTask *downloadTask))block;
|
|
|
+- (void)setDataTaskDidBecomeDownloadTaskBlock:(nullable void (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLSessionDownloadTask *downloadTask))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when a data task receives data, as handled by the `NSURLSessionDataDelegate` method `URLSession:dataTask:didReceiveData:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDataTaskDidReceiveDataBlock:(void (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSData *data))block;
|
|
|
+- (void)setDataTaskDidReceiveDataBlock:(nullable void (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSData *data))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed to determine the caching behavior of a data task, as handled by the `NSURLSessionDataDelegate` method `URLSession:dataTask:willCacheResponse:completionHandler:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDataTaskWillCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSCachedURLResponse *proposedResponse))block;
|
|
|
+- (void)setDataTaskWillCacheResponseBlock:(nullable NSCachedURLResponse * (^)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSCachedURLResponse *proposedResponse))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed once all messages enqueued for a session have been delivered, as handled by the `NSURLSessionDataDelegate` method `URLSessionDidFinishEventsForBackgroundURLSession:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDidFinishEventsForBackgroundURLSessionBlock:(void (^)(NSURLSession *session))block;
|
|
|
+- (void)setDidFinishEventsForBackgroundURLSessionBlock:(nullable void (^)(NSURLSession *session))block;
|
|
|
|
|
|
///-----------------------------------------------
|
|
|
/// @name Setting Download Task Delegate Callbacks
|
|
@@ -422,21 +424,21 @@
|
|
|
|
|
|
@param block A 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 `AFURLSessionDownloadTaskDidFailToMoveFileNotification` will be posted, with the download task as its object, and the user info of the error.
|
|
|
*/
|
|
|
-- (void)setDownloadTaskDidFinishDownloadingBlock:(NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block;
|
|
|
+- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed periodically to track download progress, as handled by the `NSURLSessionDownloadDelegate` method `URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten:totalBytesExpectedToWrite:`.
|
|
|
|
|
|
@param block A 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 `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the session manager operation queue.
|
|
|
*/
|
|
|
-- (void)setDownloadTaskDidWriteDataBlock:(void (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite))block;
|
|
|
+- (void)setDownloadTaskDidWriteDataBlock:(nullable void (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite))block;
|
|
|
|
|
|
/**
|
|
|
Sets a block to be executed when a download task has been resumed, as handled by the `NSURLSessionDownloadDelegate` method `URLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:`.
|
|
|
|
|
|
@param block A 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.
|
|
|
*/
|
|
|
-- (void)setDownloadTaskDidResumeBlock:(void (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t fileOffset, int64_t expectedTotalBytes))block;
|
|
|
+- (void)setDownloadTaskDidResumeBlock:(nullable void (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t fileOffset, int64_t expectedTotalBytes))block;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -544,3 +546,5 @@ extern NSString * const AFNetworkingTaskDidFinishErrorKey DEPRECATED_ATTRIBUTE;
|
|
|
Any error associated with the task, or the serialization of the response. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if an error exists.
|
|
|
*/
|
|
|
extern NSString * const AFNetworkingTaskDidCompleteErrorKey;
|
|
|
+
|
|
|
+NS_ASSUME_NONNULL_END
|