NetworkTaskOperation Class Reference
Inherits from | NSOperation |
Conforms to | NSURLSessionTaskDelegate |
Declared in | NetworkTaskOperation.h NetworkTaskOperation.m |
Overview
Base NSURLSessionTask operation class.
This is an abstract class is not intended to be used by itself. Instead, use one of its subclasses, NetworkDataTaskOperation
, NetworkDownloadTaskOperation
, or NetworkUploadTaskOperation
.
Tasks
Properties
-
task
The
propertyNSURLSessionTask
associated with this operation -
credential
The
propertyNSURLCredential
to be used if authentication challenge received. -
didCompleteWithDataErrorHandler
Did complete with error handler block
property -
didReceiveChallengeHandler
Did receive challenge handler block
property -
didSendBodyDataHandler
Did send body data handler block
property -
needNewBodyStreamHandler
Need new body stream handler block
property -
willPerformHTTPRedirectionHandler
Will perform HTTP redirection handler block
property -
completionQueue
The GCD queue to which completion/progress blocks will be dispatched. If
propertynil
, it will usedispatch_get_main_queue()
.
Initialization
-
– initWithSession:request:
Create NetworkTaskOperation
Inquire regarding status
-
– canRespondToChallenge
Return whether this operation respond to a challenge.
Manage operation
-
– completeOperation
Complete the operation.
Properties
completionQueue
The GCD queue to which completion/progress blocks will be dispatched. If nil
, it will use dispatch_get_main_queue()
.
@property (nonatomic, strong) dispatch_queue_t completionQueue
Discussion
Often, its useful to have the completion blocks run on the main queue (as you’re generally updating the UI). But if you’re doing something on a background thread that doesn’t rely on UI updates (or if performing tests in the absence of a UI), you might want to use a background queue.
Declared In
NetworkTaskOperation.h
credential
The NSURLCredential
to be used if authentication challenge received.
@property (nonatomic, strong) NSURLCredential *credential
Declared In
NetworkTaskOperation.h
didCompleteWithDataErrorHandler
Did complete with error handler block
@property (nonatomic, copy) DidCompleteWithDataErrorHandler didCompleteWithDataErrorHandler
Discussion
Uses the following typdef:
typedef void(^DidCompleteWithDataErrorHandler)(NetworkTaskOperation *operation,
NSData *data,
NSError *error);
Declared In
NetworkTaskOperation.h
didReceiveChallengeHandler
Did receive challenge handler block
@property (nonatomic, copy) DidReceiveChallengeHandler didReceiveChallengeHandler
Discussion
Uses the following typdef:
typedef void(^DidReceiveChallengeHandler)(NetworkTaskOperation *operation,
NSURLAuthenticationChallenge *challenge,
void(^completionHandler)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)
);
Declared In
NetworkTaskOperation.h
didSendBodyDataHandler
Did send body data handler block
@property (nonatomic, copy) DidSendBodyDataHandler didSendBodyDataHandler
Discussion
Uses the following typdef:
typedef void(^DidSendBodyDataHandler)(NetworkTaskOperation *operation,
int64_t bytesSent,
int64_t totalBytesSent,
int64_t totalBytesExpectedToSend);
Declared In
NetworkTaskOperation.h
needNewBodyStreamHandler
Need new body stream handler block
@property (nonatomic, copy) NeedNewBodyStreamHandler needNewBodyStreamHandler
Discussion
Uses the following typdef:
typedef void(^NeedNewBodyStreamHandler)(NetworkTaskOperation *operation,
void(^completionHandler)(NSInputStream *bodyStream));
Declared In
NetworkTaskOperation.h
task
The NSURLSessionTask
associated with this operation
@property (nonatomic, weak) NSURLSessionTask *task
Declared In
NetworkTaskOperation.h
willPerformHTTPRedirectionHandler
Will perform HTTP redirection handler block
@property (nonatomic, copy) WillPerformHTTPRedirectionHandler willPerformHTTPRedirectionHandler
Discussion
Uses the following typdef:
typedef void(^WillPerformHTTPRedirectionHandler)(NetworkTaskOperation *operation,
NSHTTPURLResponse *response,
NSURLRequest *request,
void(^completionHandler)(NSURLRequest *));
Declared In
NetworkTaskOperation.h
Instance Methods
canRespondToChallenge
Return whether this operation respond to a challenge.
- (BOOL)canRespondToChallenge
Return Value
YES
if it can respond to challenge. NO
if the session manager will try.
Declared In
NetworkTaskOperation.h
completeOperation
Complete the operation.
- (void)completeOperation
Declared In
NetworkTaskOperation.h
initWithSession:request:
Create NetworkTaskOperation
- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request
Parameters
- session
The
NSURLSession
for which the task operation should be created.
- request
The
NSURLRequest
for the task operation.
Return Value
Returns NetworkTaskOperation.
Declared In
NetworkTaskOperation.h