AFXMLParserResponseSerializer Class Reference

AFXMLParserResponseSerializer Class Reference

Inherits from AFHTTPResponseSerializer : NSObject
Declared in AFURLResponseSerialization.h
AFURLResponseSerialization.m

Overview

AFXMLParserResponseSerializer is a subclass of AFHTTPResponseSerializer that validates and decodes XML responses as an NSXMLParser objects.

By default, AFXMLParserResponseSerializer accepts the following MIME types, which includes the official standard, application/xml, as well as other commonly-used types:

  • application/xml
  • text/xml

+ serializer

Creates and returns a serializer with default configuration.

+ (instancetype)serializer

Declared In

AFURLResponseSerialization.h

– responseObjectForResponse:data:error:

- (id)responseObjectForResponse:(NSHTTPURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error

Declared In

AFURLResponseSerialization.h

AFStreamingMultipartFormData Class Reference

AFStreamingMultipartFormData Class Reference

Inherits from NSObject
Conforms to AFMultipartFormData
Declared in AFURLRequestSerialization.m

– appendPartWithFileURL:name:error:

Appends the HTTP header Content-Disposition: file; filename=#{generated filename}; name=#{name}" and Content-Type: #{generated mimeType}, followed by the encoded file data and the multipart form boundary.

- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError *__autoreleasing *)error

Parameters

fileURL

The URL corresponding to the file whose content will be appended to the form. This parameter must not be nil.

name

The name to be associated with the specified data. This parameter must not be nil.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Return Value

YES if the file data was successfully appended, otherwise NO.

Discussion

The filename and MIME type for this data in the form will be automatically generated, using the last path component of the fileURL and system associated MIME type for the fileURL extension, respectively.

Declared In

AFURLRequestSerialization.h

– appendPartWithFileURL:name:fileName:mimeType:error:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the encoded file data and the multipart form boundary.

- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType error:(NSError *__autoreleasing *)error

Parameters

fileURL

The URL corresponding to the file whose content will be appended to the form. This parameter must not be nil.

name

The name to be associated with the specified data. This parameter must not be nil.

fileName

The file name to be used in the Content-Disposition header. This parameter must not be nil.

mimeType

The declared MIME type of the file data. This parameter must not be nil.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Return Value

YES if the file data was successfully appended otherwise NO.

Declared In

AFURLRequestSerialization.h

– appendPartWithInputStream:name:fileName:length:mimeType:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the data from the input stream and the multipart form boundary.

- (void)appendPartWithInputStream:(NSInputStream *)inputStream name:(NSString *)name fileName:(NSString *)fileName length:(int64_t)length mimeType:(NSString *)mimeType

Parameters

inputStream

The input stream to be appended to the form data

name

The name to be associated with the specified input stream. This parameter must not be nil.

fileName

The filename to be associated with the specified input stream. This parameter must not be nil.

length

The length of the specified input stream in bytes.

mimeType

The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

– appendPartWithFileData:name:fileName:mimeType:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the encoded file data and the multipart form boundary.

- (void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType

Parameters

data

The data to be encoded and appended to the form data.

name

The name to be associated with the specified data. This parameter must not be nil.

fileName

The filename to be associated with the specified data. This parameter must not be nil.

mimeType

The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

– appendPartWithFormData:name:

Appends the HTTP headers Content-Disposition: form-data; name=#{name}", followed by the encoded data and the multipart form boundary.

- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name

Parameters

data

The data to be encoded and appended to the form data.

name

The name to be associated with the specified data. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

– appendPartWithHeaders:body:

Appends HTTP headers, followed by the encoded data and the multipart form boundary.

- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body

Parameters

headers

The HTTP headers to be appended to the form data.

body

The data to be encoded and appended to the form data. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

– throttleBandwidthWithPacketSize:delay:

Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream.

- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes delay:(NSTimeInterval)delay

Parameters

numberOfBytes

Maximum packet size, in number of bytes. The default packet size for an input stream is 16kb.

delay

Duration of delay each time a packet is read. By default, no delay is set.

Discussion

When uploading over a 3G or EDGE connection, requests may fail with “request body stream exhausted”. Setting a maximum packet size and delay according to the recommended values (kAFUploadStream3GSuggestedPacketSize and kAFUploadStream3GSuggestedDelay) lowers the risk of the input stream exceeding its allocated bandwidth. Unfortunately, there is no definite way to distinguish between a 3G, EDGE, or LTE connection over NSURLConnection. As such, it is not recommended that you throttle bandwidth based solely on network reachability. Instead, you should consider checking for the “request body stream exhausted” in a failure block, and then retrying the request with throttled bandwidth.

Declared In

AFURLRequestSerialization.h

KWUserDefinedMatcher Class Reference

KWUserDefinedMatcher Class Reference

Inherits from KWMatcher : NSObject
Declared in KWUserDefinedMatcher.h
KWUserDefinedMatcher.m

– matcherMethodWithoutArguments

TODO: find a way of doing this that: - doesn’t require dummy methods (create the method signatures manually) - supports an unlimited number of arguments

- (void)matcherMethodWithoutArguments

Declared In

KWUserDefinedMatcher.m

KWExample Class Reference

KWExample Class Reference

Inherits from NSObject
Conforms to KWExampleNodeVisitor
KWReporting
Declared in KWExample.h
KWExample.m

– pendingNotFinished

Pending cases will be marked yellow by XCode as not finished, because their description differs for [SenTestCaseRun start] and [SenTestCaseRun stop] methods

- (NSString *)pendingNotFinished

Declared In

KWExample.m

AFURLSessionManager Class Reference

AFURLSessionManager Class Reference

Inherits from NSObject
Conforms to NSCopying
NSSecureCoding
NSURLSessionDataDelegate
NSURLSessionDelegate
NSURLSessionDownloadDelegate
NSURLSessionTaskDelegate
Declared in AFURLSessionManager.h
AFURLSessionManager.m

Overview

AFURLSessionManager 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 AFHTTPSessionManager, which adds functionality specific to making HTTP requests. If you are looking to extend AFURLSessionManager specifically for HTTP, consider subclassing AFHTTPSessionManager instead.

NSURLSession & NSURLSessionTask Delegate Methods

AFURLSessionManager 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: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 AFNetworkReachabilityManager for more details.

NSCoding Caveats

  • Encoded managers do not include any block properties. Be sure to set delegate callback blocks when using -initWithCoder: or NSKeyedUnarchiver.

NSCopying Caveats

  • -copy and -copyWithZone: return a new manager with a new NSURLSession created 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.

Other Methods

  session

The managed session.

@property (readonly, nonatomic, strong) NSURLSession *session

Declared In

AFURLSessionManager.h

  operationQueue

The operation queue on which delegate callbacks are run.

@property (readonly, nonatomic, strong) NSOperationQueue *operationQueue

Declared In

AFURLSessionManager.h

  responseSerializer

Responses sent from the server in data tasks created with dataTaskWithRequest:success:failure: and run using the GET / POST / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance of AFJSONResponseSerializer.

@property (nonatomic, strong) id<AFURLResponseSerialization> responseSerializer

Discussion

Warning: responseSerializer must not be nil.

Declared In

AFURLSessionManager.h

Managing Security Policy

  securityPolicy

The security policy used by created session to evaluate server trust for secure connections. AFURLSessionManager uses the defaultPolicy unless otherwise specified.

@property (nonatomic, strong) AFSecurityPolicy *securityPolicy

Declared In

AFURLSessionManager.h

Monitoring Network Reachability

  reachabilityManager

The network reachability manager. AFURLSessionManager uses the sharedManager by default.

@property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager

Declared In

AFURLSessionManager.h

Getting Session Tasks

  tasks

The data, upload, and download tasks currently run by the managed session.

@property (readonly, nonatomic, strong) NSArray<NSURLSessionTask*> *tasks

Declared In

AFURLSessionManager.h

  dataTasks

The data tasks currently run by the managed session.

@property (readonly, nonatomic, strong) NSArray<NSURLSessionDataTask*> *dataTasks

Declared In

AFURLSessionManager.h

  uploadTasks

The upload tasks currently run by the managed session.

@property (readonly, nonatomic, strong) NSArray<NSURLSessionUploadTask*> *uploadTasks

Declared In

AFURLSessionManager.h

  downloadTasks

The download tasks currently run by the managed session.

@property (readonly, nonatomic, strong) NSArray<NSURLSessionDownloadTask*> *downloadTasks

Declared In

AFURLSessionManager.h

Managing Callback Queues

  completionQueue

The dispatch queue for completionBlock. If NULL (default), the main queue is used.

@property (nonatomic, strong, nullable) dispatch_queue_t completionQueue

Declared In

AFURLSessionManager.h

  completionGroup

The dispatch group for completionBlock. If NULL (default), a private dispatch group is used.

@property (nonatomic, strong, nullable) dispatch_group_t completionGroup

Declared In

AFURLSessionManager.h

Working Around System Bugs

  attemptsToRecreateUploadTasksForBackgroundSessions

Whether to attempt to retry creation of upload tasks for background sessions when initial call returns nil. NO by default.

@property (nonatomic, assign) BOOL attemptsToRecreateUploadTasksForBackgroundSessions

Discussion

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.

Declared In

AFURLSessionManager.h

Initialization

– initWithSessionConfiguration:

Creates and returns a manager for a session created with the specified configuration. This is the designated initializer.

- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration

Parameters

configuration

The configuration used to create the managed session.

Return Value

A manager for a newly-created session.

Declared In

AFURLSessionManager.h

– invalidateSessionCancelingTasks:

Invalidates the managed session, optionally canceling pending tasks.

- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks

Parameters

cancelPendingTasks

Whether or not to cancel pending tasks.

Declared In

AFURLSessionManager.h

Running Data Tasks

– dataTaskWithRequest:completionHandler:

Creates an NSURLSessionDataTask with the specified request.

- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , id _Nullable responseObject , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

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.

Declared In

AFURLSessionManager.h

– dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:

Creates an NSURLSessionDataTask with the specified request.

- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request uploadProgress:(nullable void ( ^ ) ( NSProgress *uploadProgress ))uploadProgressBlock downloadProgress:(nullable void ( ^ ) ( NSProgress *downloadProgress ))downloadProgressBlock completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , id _Nullable responseObject , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

uploadProgressBlock

A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.

downloadProgressBlock

A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.

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.

Declared In

AFURLSessionManager.h

Running Upload Tasks

– uploadTaskWithRequest:fromFile:progress:completionHandler:

Creates an NSURLSessionUploadTask with the specified request for a local file.

- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL progress:(nullable void ( ^ ) ( NSProgress *uploadProgress ))uploadProgressBlock completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , id _Nullable responseObject , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

fileURL

A URL to the local file to be uploaded.

uploadProgressBlock

A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.

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.

Declared In

AFURLSessionManager.h

– uploadTaskWithRequest:fromData:progress:completionHandler:

Creates an NSURLSessionUploadTask with the specified request for an HTTP body.

- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(nullable NSData *)bodyData progress:(nullable void ( ^ ) ( NSProgress *uploadProgress ))uploadProgressBlock completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , id _Nullable responseObject , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

bodyData

A data object containing the HTTP body to be uploaded.

uploadProgressBlock

A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.

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.

Declared In

AFURLSessionManager.h

– uploadTaskWithStreamedRequest:progress:completionHandler:

Creates an NSURLSessionUploadTask with the specified streaming request.

- (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request progress:(nullable void ( ^ ) ( NSProgress *uploadProgress ))uploadProgressBlock completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , id _Nullable responseObject , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

uploadProgressBlock

A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.

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.

Declared In

AFURLSessionManager.h

Running Download Tasks

– downloadTaskWithRequest:progress:destination:completionHandler:

Creates an NSURLSessionDownloadTask with the specified request.

- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request progress:(nullable void ( ^ ) ( NSProgress *downloadProgress ))downloadProgressBlock destination:(nullable NSURL *( ^ ) ( NSURL *targetPath , NSURLResponse *response ))destination completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , NSURL *_Nullable filePath , NSError *_Nullable error ))completionHandler

Parameters

request

The HTTP request for the request.

downloadProgressBlock

A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.

destination

A 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.

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.

Discussion

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.

Declared In

AFURLSessionManager.h

– downloadTaskWithResumeData:progress:destination:completionHandler:

Creates an NSURLSessionDownloadTask with the specified resume data.

- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData progress:(nullable void ( ^ ) ( NSProgress *downloadProgress ))downloadProgressBlock destination:(nullable NSURL *( ^ ) ( NSURL *targetPath , NSURLResponse *response ))destination completionHandler:(nullable void ( ^ ) ( NSURLResponse *response , NSURL *_Nullable filePath , NSError *_Nullable error ))completionHandler

Parameters

resumeData

The data used to resume downloading.

downloadProgressBlock

A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.

destination

A 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.

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.

Declared In

AFURLSessionManager.h

Getting Progress for Tasks

– uploadProgressForTask:

Returns the upload progress of the specified task.

- (nullable NSProgress *)uploadProgressForTask:(NSURLSessionTask *)task

Parameters

task

The session task. Must not be nil.

Return Value

An NSProgress object reporting the upload progress of a task, or nil if the progress is unavailable.

Declared In

AFURLSessionManager.h

– downloadProgressForTask:

Returns the download progress of the specified task.

- (nullable NSProgress *)downloadProgressForTask:(NSURLSessionTask *)task

Parameters

task

The session task. Must not be nil.

Return Value

An NSProgress object reporting the download progress of a task, or nil if the progress is unavailable.

Declared In

AFURLSessionManager.h

Setting Session Delegate Callbacks

– setSessionDidBecomeInvalidBlock:

Sets a block to be executed when the managed session becomes invalid, as handled by the NSURLSessionDelegate method URLSession:didBecomeInvalidWithError:.

- (void)setSessionDidBecomeInvalidBlock:(nullable void ( ^ ) ( NSURLSession *session , NSError *error ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setSessionDidReceiveAuthenticationChallengeBlock:

Sets a block to be executed when a connection level authentication challenge has occurred, as handled by the NSURLSessionDelegate method URLSession:didReceiveChallenge:completionHandler:.

- (void)setSessionDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition ( ^ ) ( NSURLSession *session , NSURLAuthenticationChallenge *challenge , NSURLCredential *_Nullable __autoreleasing *_Nullable credential ))block

Parameters

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.

Declared In

AFURLSessionManager.h

Setting Task Delegate Callbacks

– setTaskNeedNewBodyStreamBlock:

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 NSURLSessionTaskDelegate method URLSession:task:needNewBodyStream:.

- (void)setTaskNeedNewBodyStreamBlock:(nullable NSInputStream *( ^ ) ( NSURLSession *session , NSURLSessionTask *task ))block

Parameters

block

A block object to be executed when a task requires a new request body stream.

Declared In

AFURLSessionManager.h

– setTaskWillPerformHTTPRedirectionBlock:

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:.

- (void)setTaskWillPerformHTTPRedirectionBlock:(nullable NSURLRequest *( ^ ) ( NSURLSession *session , NSURLSessionTask *task , NSURLResponse *response , NSURLRequest *request ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setTaskDidReceiveAuthenticationChallengeBlock:

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:.

- (void)setTaskDidReceiveAuthenticationChallengeBlock:(nullable NSURLSessionAuthChallengeDisposition ( ^ ) ( NSURLSession *session , NSURLSessionTask *task , NSURLAuthenticationChallenge *challenge , NSURLCredential *_Nullable __autoreleasing *_Nullable credential ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setTaskDidSendBodyDataBlock:

Sets a block to be executed periodically to track upload progress, as handled by the NSURLSessionTaskDelegate method URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:.

- (void)setTaskDidSendBodyDataBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionTask *task , int64_t bytesSent , int64_t totalBytesSent , int64_t totalBytesExpectedToSend ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setTaskDidCompleteBlock:

Sets a block to be executed as the last message related to a specific task, as handled by the NSURLSessionTaskDelegate method URLSession:task:didCompleteWithError:.

- (void)setTaskDidCompleteBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionTask *task , NSError *_Nullable error ))block

Parameters

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.

Declared In

AFURLSessionManager.h

Setting Data Task Delegate Callbacks

– setDataTaskDidReceiveResponseBlock:

Sets a block to be executed when a data task has received a response, as handled by the NSURLSessionDataDelegate method URLSession:dataTask:didReceiveResponse:completionHandler:.

- (void)setDataTaskDidReceiveResponseBlock:(nullable NSURLSessionResponseDisposition ( ^ ) ( NSURLSession *session , NSURLSessionDataTask *dataTask , NSURLResponse *response ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDataTaskDidBecomeDownloadTaskBlock:

Sets a block to be executed when a data task has become a download task, as handled by the NSURLSessionDataDelegate method URLSession:dataTask:didBecomeDownloadTask:.

- (void)setDataTaskDidBecomeDownloadTaskBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionDataTask *dataTask , NSURLSessionDownloadTask *downloadTask ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDataTaskDidReceiveDataBlock:

Sets a block to be executed when a data task receives data, as handled by the NSURLSessionDataDelegate method URLSession:dataTask:didReceiveData:.

- (void)setDataTaskDidReceiveDataBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionDataTask *dataTask , NSData *data ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDataTaskWillCacheResponseBlock:

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:.

- (void)setDataTaskWillCacheResponseBlock:(nullable NSCachedURLResponse *( ^ ) ( NSURLSession *session , NSURLSessionDataTask *dataTask , NSCachedURLResponse *proposedResponse ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDidFinishEventsForBackgroundURLSessionBlock:

Sets a block to be executed once all messages enqueued for a session have been delivered, as handled by the NSURLSessionDataDelegate method URLSessionDidFinishEventsForBackgroundURLSession:.

- (void)setDidFinishEventsForBackgroundURLSessionBlock:(nullable void ( ^ ) ( NSURLSession *session ))block

Parameters

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.

Declared In

AFURLSessionManager.h

Setting Download Task Delegate Callbacks

– setDownloadTaskDidFinishDownloadingBlock:

Sets a block to be executed when a download task has completed a download, as handled by the NSURLSessionDownloadDelegate method URLSession:downloadTask:didFinishDownloadingToURL:.

- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL *_Nullable ( ^ ) ( NSURLSession *session , NSURLSessionDownloadTask *downloadTask , NSURL *location ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDownloadTaskDidWriteDataBlock:

Sets a block to be executed periodically to track download progress, as handled by the NSURLSessionDownloadDelegate method URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten:totalBytesExpectedToWrite:.

- (void)setDownloadTaskDidWriteDataBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionDownloadTask *downloadTask , int64_t bytesWritten , int64_t totalBytesWritten , int64_t totalBytesExpectedToWrite ))block

Parameters

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.

Declared In

AFURLSessionManager.h

– setDownloadTaskDidResumeBlock:

Sets a block to be executed when a download task has been resumed, as handled by the NSURLSessionDownloadDelegate method URLSession:downloadTask:didResumeAtOffset:expectedTotalBytes:.

- (void)setDownloadTaskDidResumeBlock:(nullable void ( ^ ) ( NSURLSession *session , NSURLSessionDownloadTask *downloadTask , int64_t fileOffset , int64_t expectedTotalBytes ))block

Parameters

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.

Declared In

AFURLSessionManager.h

html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace, monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}*{box-sizing:border-box}.clear{clear:both}.clearfix:before,.container:before,article #content:before,article #content footer:before,.clearfix:after,.container:after,article #content:after,article #content footer:after{clear:both;display:table;content:""}.xcode .hide-in-xcode{display:none}body{font:62.5% -apple-system-font,"Helvetica Neue",Helvetica,sans-serif;background:#f2f2f2}@media (max-width: 650px){body{background-color:#fff}}h1,h2,h3{font-weight:300;color:#808080}h1{font-size:2em;color:#000}h4{font-size:13px;line-height:1.5;margin:21px 0 0 0}a{color:#08c;text-decoration:none}pre,code{font-family:"Source Code Pro",Monaco,Menlo,Consolas,monospace;word-wrap:break-word}pre>code,.method-declaration code{display:inline-block;font-size:.85em;padding:4px 0 4px 10px;border-left:5px solid rgba(0,155,51,0.2)}pre>code:before,.method-declaration code:before{content:"Objective-C";display:block;font:9px/1 -apple-system-font,"Helvetica Neue",Helvetica,sans-serif;color:#009b33;text-transform:uppercase;letter-spacing:2px;padding-bottom:6px}pre>code{font-size:inherit}table,th,td{border:1px solid #e9e9e9}table{width:100%}th,td{padding:7px}th>:first-child,td>:first-child{margin-top:0}th>:last-child,td>:last-child{margin-bottom:0}.container{max-width:980px;padding:0 10px;margin:0 auto}@media (max-width: 650px){.container{padding:0}}header{position:fixed;top:0;left:0;width:100%;z-index:2;background:#414141;color:#fff;font-size:1.1em;line-height:25px;letter-spacing:.05em}header #library-title{float:left}header #developer-home{float:right}header h1{font-size:inherit;font-weight:inherit;margin:0}header p{margin:0}header h1,header a{color:inherit}@media (max-width: 650px){header .container{padding:0 10px}}aside{position:fixed;top:25px;left:0;width:100%;height:25px;z-index:2;font-size:1.1em}aside #header-buttons{background:rgba(255,255,255,0.8);margin:0 1px;padding:0;list-style:none;text-align:right;line-height:32px}aside #header-buttons li{display:inline-block;cursor:pointer;padding:0 10px}aside #header-buttons label,aside #header-buttons select{cursor:inherit}aside #header-buttons #on-this-page{position:relative}aside #header-buttons #on-this-page .chevron{display:inline-block;width:14px;height:4px;position:relative}aside #header-buttons #on-this-page .chevron .chevy{background:#878787;height:2px;position:absolute;width:10px}aside #header-buttons #on-this-page .chevron .chevy.chevron-left{left:0;transform:rotateZ(45deg) scale(0.6)}aside #header-buttons #on-this-page .chevron .chevy.chevron-right{right:0;transform:rotateZ(-45deg) scale(0.6)}aside #header-buttons #on-this-page #jump-to{opacity:0;font-size:16px;position:absolute;top:5px;left:0;width:100%;height:100%}article{margin-top:25px}article #content{background:#fff;border:1px solid #e9e9e9;padding:15px 25px 30px 25px;font-size:1.4em;line-height:1.45;position:relative}@media (max-width: 650px){article #content{padding:15px 10px 20px 10px;border:none}}article #content .navigation-top{position:absolute;top:15px;right:25px}article #content .title{margin:21px 0 0 0;padding:15px 0}article #content p{color:#414141;margin:0 0 15px 0}article #content th p:last-child,article #content td p:last-child{margin-bottom:0}article #content main ul{list-style:none;margin-left:24px;margin-bottom:12px;padding:0}article #content main ul li{position:relative;padding-left:1.3em}article #content main ul li:before{content:"\02022";color:#414141;font-size:1.08em;line-height:1;position:absolute;left:0;padding-top:2px}article #content footer .footer-copyright{margin:70px 25px 10px 0}article #content footer p{font-size:.71em;color:#a0a0a0}.index-container{-webkit-flex-direction:column;flex-direction:column}@media (min-width: 768px){.index-container{display:flex;-webkit-flex-direction:row;flex-direction:row;-webkit-flex-wrap:wrap;flex-wrap:wrap}}.index-container .index-column{-webkit-flex:1 1 33%;flex:1 1 33%}.section-specification table{width:auto}.section-specification table th{text-align:left}.method-title{margin-left:-15px;margin-bottom:8px;transition:margin-left .3s ease-out}.section-method.hide .method-title{margin-left:0}.method-title code{font-weight:400;font-size:.85em}.method-info{background:#f9f9f9;border-bottom:1px solid #e9e9e9;margin:0 -25px;padding:20px 25px 0 25px;transition:height .3s ease-out;position:relative}.method-info .pointy-thing{background:#fff;height:10px;border-bottom:1px solid #e9e9e9;margin:-20px -25px 16px -25px}.method-info .pointy-thing:before{display:inline-block;content:"";background:#f9f9f9;border:1px solid #e9e9e9;border-bottom:0;border-right:0;position:absolute;left:21px;top:3px;width:12px;height:12px;-webkit-transform:rotate(45deg);transform:rotate(45deg) }.method-info .method-subsection{margin-bottom:15px}.method-info .method-subsection .argument-name{width:1px;text-align:right}.method-info .method-subsection .argument-name code{color:#808080;font-style:italic;font-weight:400}.section-method.hide .method-info{height:0 !important;overflow:hidden;display:none}.section-method.hide.animating .method-info{display:block}.section-method.animating .method-info{overflow:hidden}@media print{body{background:#fff;padding:8px}header{position:static;background:#fff;color:#000}aside{display:none}.container{max-width:none;padding:0}article{margin-top:0}article #content{border:0;background:#fff;padding:15px 0 0 0}article #content .title{margin-top:0;padding-top:0}.method-info,.method-info .pointy-thing{background:#fff}}.xcode header,.xcode aside{display:none}.xcode .container{padding:0}.xcode article{margin-top:0}.xcode article #content{border:0;margin:0}.xcode .method-info,.section-method.hide .xcode .method-info{max-height:auto;overflow:visible}.xcode .method-info.hiding,.section-method.hide .xcode .method-info.hiding{display:block}
function $() { return document.querySelector.apply(document, arguments); } if (navigator.userAgent.indexOf("Xcode") != -1) { document.documentElement.classList.add("xcode"); } var jumpTo = $("#jump-to"); if (jumpTo) { jumpTo.addEventListener("change", function(e) { location.hash = this.options[this.selectedIndex].value; }); } function hashChanged() { if (/^#\/\/api\//.test(location.hash)) { var element = document.querySelector("a[name='" + location.hash.substring(1) + "']"); if (!element) { return; } element = element.parentNode; element.classList.remove("hide"); fixScrollPosition(element); } } function fixScrollPosition(element) { var scrollTop = element.offsetTop - 150; document.documentElement.scrollTop = scrollTop; document.body.scrollTop = scrollTop; } [].forEach.call(document.querySelectorAll(".section-method"), function(element) { element.classList.add("hide"); element.querySelector(".method-title a").addEventListener("click", function(e) { var info = element.querySelector(".method-info"), infoContainer = element.querySelector(".method-info-container"); element.classList.add("animating"); info.style.height = (infoContainer.clientHeight + 40) + "px"; fixScrollPosition(element); element.classList.toggle("hide"); if (element.classList.contains("hide")) { e.preventDefault(); } setTimeout(function() { element.classList.remove("animating"); }, 300); }); }); window.addEventListener("hashchange", hashChanged); hashChanged();