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
-
taskThe
propertyNSURLSessionTaskassociated with this operation -
credentialThe
propertyNSURLCredentialto be used if authentication challenge received. -
didCompleteWithDataErrorHandlerDid complete with error handler block
property -
didReceiveChallengeHandlerDid receive challenge handler block
property -
didSendBodyDataHandlerDid send body data handler block
property -
needNewBodyStreamHandlerNeed new body stream handler block
property -
willPerformHTTPRedirectionHandlerWill perform HTTP redirection handler block
property -
completionQueueThe 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
-
– canRespondToChallengeReturn whether this operation respond to a challenge.
Manage operation
-
– completeOperationComplete 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 completionQueueDiscussion
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.hcredential
The NSURLCredential to be used if authentication challenge received.
@property (nonatomic, strong) NSURLCredential *credentialDeclared In
NetworkTaskOperation.hdidCompleteWithDataErrorHandler
Did complete with error handler block
@property (nonatomic, copy) DidCompleteWithDataErrorHandler didCompleteWithDataErrorHandlerDiscussion
Uses the following typdef:
typedef void(^DidCompleteWithDataErrorHandler)(NetworkTaskOperation *operation,
NSData *data,
NSError *error);
Declared In
NetworkTaskOperation.hdidReceiveChallengeHandler
Did receive challenge handler block
@property (nonatomic, copy) DidReceiveChallengeHandler didReceiveChallengeHandlerDiscussion
Uses the following typdef:
typedef void(^DidReceiveChallengeHandler)(NetworkTaskOperation *operation,
NSURLAuthenticationChallenge *challenge,
void(^completionHandler)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)
);
Declared In
NetworkTaskOperation.hdidSendBodyDataHandler
Did send body data handler block
@property (nonatomic, copy) DidSendBodyDataHandler didSendBodyDataHandlerDiscussion
Uses the following typdef:
typedef void(^DidSendBodyDataHandler)(NetworkTaskOperation *operation,
int64_t bytesSent,
int64_t totalBytesSent,
int64_t totalBytesExpectedToSend);
Declared In
NetworkTaskOperation.hneedNewBodyStreamHandler
Need new body stream handler block
@property (nonatomic, copy) NeedNewBodyStreamHandler needNewBodyStreamHandlerDiscussion
Uses the following typdef:
typedef void(^NeedNewBodyStreamHandler)(NetworkTaskOperation *operation,
void(^completionHandler)(NSInputStream *bodyStream));
Declared In
NetworkTaskOperation.htask
The NSURLSessionTask associated with this operation
@property (nonatomic, weak) NSURLSessionTask *taskDeclared In
NetworkTaskOperation.hwillPerformHTTPRedirectionHandler
Will perform HTTP redirection handler block
@property (nonatomic, copy) WillPerformHTTPRedirectionHandler willPerformHTTPRedirectionHandlerDiscussion
Uses the following typdef:
typedef void(^WillPerformHTTPRedirectionHandler)(NetworkTaskOperation *operation,
NSHTTPURLResponse *response,
NSURLRequest *request,
void(^completionHandler)(NSURLRequest *));
Declared In
NetworkTaskOperation.hInstance Methods
canRespondToChallenge
Return whether this operation respond to a challenge.
- (BOOL)canRespondToChallengeReturn Value
YES if it can respond to challenge. NO if the session manager will try.
Declared In
NetworkTaskOperation.hcompleteOperation
Complete the operation.
- (void)completeOperationDeclared In
NetworkTaskOperation.hinitWithSession:request:
Create NetworkTaskOperation
- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)requestParameters
- session
The
NSURLSessionfor which the task operation should be created.
- request
The
NSURLRequestfor the task operation.
Return Value
Returns NetworkTaskOperation.
Declared In
NetworkTaskOperation.h