Type Method

sendAsynchronousRequest:queue:completionHandler:

Loads the data for a URL request and executes a handler block on an operation queue when the request completes or fails.

Declaration

+ (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse *response, NSData *data, NSError *connectionError))handler;

Parameters

request

The URL request to load. The request object is deep-copied as part of the initialization process. Changes made to request after this method returns do not affect the request that is used for the loading process.

queue

The operation queue to which the handler block is dispatched when the request completes or failed.

handler

The handler block to execute.

Discussion

If the request completes successfully, the data parameter of the handler block contains the resource data, and the error parameter is nil. If the request fails, the data parameter is nil and the error parameter contain information about the failure.

If authentication is required in order to download the request, the required credentials must be specified as part of the URL. If authentication fails, or credentials are missing, the connection will attempt to continue without credentials. If the request finishes with a 401 Unauthorized status code, the response parameter is nil, the data parameter contains the resource data, and the error parameter is an NSError with the NSURLErrorUserCancelledAuthentication code in the NSURLErrorDomain error domain.

See Also

Loading Data Asynchronously

+ connectionWithRequest:delegate:

Creates and returns an initialized URL connection and begins to load the data for the URL request.

Deprecated
- initWithRequest:delegate:

Returns an initialized URL connection and begins to load the data for the URL request.

Deprecated
- initWithRequest:delegate:startImmediately:

Returns an initialized URL connection and begins to load the data for the URL request, if specified.

Deprecated
- start

Causes the connection to begin loading data, if it has not already.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software