| | |
| | | ### `NSURLSessionDownloadDelegate` |
| | | |
| | | - `URLSession:downloadTask:didFinishDownloadingToURL:` |
| | | - `URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten:totalBytesExpectedToWrite:` |
| | | - `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. |
| | |
| | | */ |
| | | @property (nonatomic, strong, nullable) dispatch_group_t completionGroup; |
| | | |
| | | ///--------------------------------- |
| | | /// @name Working Around System Bugs |
| | | ///--------------------------------- |
| | | |
| | | /** |
| | | Whether to attempt to retry creation of upload tasks for background sessions when initial call returns `nil`. `NO` by default. |
| | | |
| | | @bug As of iOS 7.0, there is a bug where upload tasks created for background tasks are sometimes `nil`. As a workaround, if this property is `YES`, AFNetworking will follow Apple's recommendation to try creating the task again. |
| | | |
| | | @see https://github.com/AFNetworking/AFNetworking/issues/1675 |
| | | */ |
| | | @property (nonatomic, assign) BOOL attemptsToRecreateUploadTasksForBackgroundSessions; |
| | | |
| | | ///--------------------- |
| | | /// @name Initialization |
| | | ///--------------------- |
| | |
| | | - (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration NS_DESIGNATED_INITIALIZER; |
| | | |
| | | /** |
| | | Invalidates the managed session, optionally canceling pending tasks. |
| | | |
| | | @param cancelPendingTasks Whether or not to cancel pending tasks. |
| | | */ |
| | | - (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks DEPRECATED_ATTRIBUTE; |
| | | |
| | | /** |
| | | Invalidates the managed session, optionally canceling pending tasks and optionally resets given session. |
| | | |
| | | @param cancelPendingTasks Whether or not to cancel pending tasks. |
| | |
| | | ///------------------------- |
| | | /// @name Running Data Tasks |
| | | ///------------------------- |
| | | |
| | | /** |
| | | Creates an `NSURLSessionDataTask` with the specified request. |
| | | |
| | | @param request The HTTP request for the request. |
| | | @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:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler DEPRECATED_ATTRIBUTE; |
| | | |
| | | /** |
| | | Creates an `NSURLSessionDataTask` with the specified request. |
| | |
| | | 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. |
| | | |
| | | @warning Implementing a session authentication challenge handler yourself totally bypasses AFNetworking's security policy defined in `AFSecurityPolicy`. Make sure you fully understand the implications before implementing a custom session authentication challenge handler. If you do not want to bypass AFNetworking's security policy, use `setTaskDidReceiveAuthenticationChallengeBlock:` instead. |
| | | |
| | | @see -securityPolicy |
| | | @see -setTaskDidReceiveAuthenticationChallengeBlock: |
| | | */ |
| | | - (void)setSessionDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * _Nullable __autoreleasing * _Nullable credential))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. |
| | | |
| | | @param authenticationChallengeHandler A block object to be executed when a session task has received a request specific authentication challenge. |
| | | |
| | | 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 AFNetworking to handle it. If you want AFNetworking to handle the authentication challenge, just return `@(NSURLSessionAuthChallengePerformDefaultHandling)`. For example, you certainly want AFNetworking 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: |
| | | |
| | | 1. Return `nil` from 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. |
| | | 2. Return an `NSError` object from the authentication challenge handler. You **MUST NOT** call the completion handler when returning an `NSError `. 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. |
| | | 3. Return an `NSURLCredential` object from the authentication challenge handler. You **MUST NOT** call the completion handler when returning an `NSURLCredential`. The returned credentials will be used to fulfil the challenge. Use this when you can get credentials without presenting a user interface. |
| | | 4. Return an `NSNumber` object wrapping an `NSURLSessionAuthChallengeDisposition`. Supported values are `@(NSURLSessionAuthChallengePerformDefaultHandling)`, `@(NSURLSessionAuthChallengeCancelAuthenticationChallenge)` and `@(NSURLSessionAuthChallengeRejectProtectionSpace)`. You **MUST NOT** call the completion handler when returning an `NSNumber`. |
| | | |
| | | 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](https://developer.apple.com/reference/foundation/nsurlsession?language=objc) and [URL Session Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html). |
| | | |
| | | @see -securityPolicy |
| | | */ |
| | | - (void)setTaskDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition (^)(NSURLSession *session, NSURLSessionTask *task, NSURLAuthenticationChallenge *challenge, NSURLCredential * _Nullable __autoreleasing * _Nullable credential))block; |
| | | - (void)setAuthenticationChallengeHandler:(id (^)(NSURLSession *session, NSURLSessionTask *task, NSURLAuthenticationChallenge *challenge, void (^completionHandler)(NSURLSessionAuthChallengeDisposition , NSURLCredential * _Nullable)))authenticationChallengeHandler; |
| | | |
| | | /** |
| | | 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 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. |
| | | */ |
| | | #if AF_CAN_INCLUDE_SESSION_TASK_METRICS |
| | | - (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block; |
| | | - (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)); |
| | | #endif |
| | | ///------------------------------------------- |
| | | /// @name Setting Data Task Delegate Callbacks |
| | |
| | | - (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * _Nullable (^)(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:`. |
| | | Sets a block to be executed periodically to track download progress, as handled by the `NSURLSessionDownloadDelegate` method `URLSession:downloadTask:didWriteData: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. |
| | | */ |
| | |
| | | FOUNDATION_EXPORT NSString * const AFURLSessionDidInvalidateNotification; |
| | | |
| | | /** |
| | | Posted when a session download task finished moving the temporary download file to a specified destination successfully. |
| | | */ |
| | | FOUNDATION_EXPORT NSString * const AFURLSessionDownloadTaskDidMoveFileSuccessfullyNotification; |
| | | |
| | | /** |
| | | Posted when a session download task encountered an error when moving the temporary download file to a specified destination. |
| | | */ |
| | | FOUNDATION_EXPORT NSString * const AFURLSessionDownloadTaskDidFailToMoveFileNotification; |