VKHTTPOperation Class Reference

Inherits from VKOperation : NSOperation
Conforms to NSCoding
NSCopying
NSURLConnectionDataDelegate
NSURLConnectionDelegate
Declared in VKHTTPOperation.h
VKHTTPOperation.m

Overview

VK URL operation subclassing NSOperation. Based on AFNetworking library ( https://github.com/AFNetworking/AFNetworking )

Other Methods

+ operationWithRequest:

Creates new operation with prepared request.

+ (instancetype)operationWithRequest:(VKRequest *)request

Parameters

request

Prepared VK request to API

Return Value

Initialized operation

Discussion

Creates new operation with prepared request.

Declared In

VKHTTPOperation.h

Accessing Run Loop Modes

  runLoopModes

The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing NSRunLoopCommonModes.

@property (nonatomic, strong) NSSet *runLoopModes

Discussion

The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing NSRunLoopCommonModes.

Declared In

VKHTTPOperation.h

Getting URL Connection Information

  vkRequest

The vk request initialized that operation

@property (readonly, nonatomic, weak) VKRequest *vkRequest

Discussion

The vk request initialized that operation

Declared In

VKHTTPOperation.h

  request

The request used by the operation’s connection.

@property (readonly, nonatomic, strong) NSURLRequest *request

Discussion

The request used by the operation’s connection.

Declared In

VKHTTPOperation.h

  error

The error, if any, that occurred in the lifecycle of the request.

@property (readonly, nonatomic, strong) NSError *error

Discussion

The error, if any, that occurred in the lifecycle of the request.

Declared In

VKHTTPOperation.h

Getting Response Data

  responseData

The data received during the request.

@property (readonly, nonatomic, strong) NSData *responseData

Discussion

The data received during the request.

Declared In

VKHTTPOperation.h

  responseString

The string representation of the response data.

@property (readonly, nonatomic, copy) NSString *responseString

Discussion

The string representation of the response data.

Declared In

VKHTTPOperation.h

  responseJson

The json representation of the response data.

@property (readonly, nonatomic, copy) id responseJson

Discussion

The json representation of the response data.

Declared In

VKHTTPOperation.h

  response

The last HTTP response received by the operation’s connection.

@property (readonly, nonatomic, strong) NSHTTPURLResponse *response

Discussion

The last HTTP response received by the operation’s connection.

Declared In

VKHTTPOperation.h

  successCallbackQueue

The callback dispatch queue on success. If NULL (default), the main queue is used.

@property (nonatomic, assign) dispatch_queue_t successCallbackQueue

Discussion

The callback dispatch queue on success. If NULL (default), the main queue is used.

Declared In

VKHTTPOperation.h

  failureCallbackQueue

The callback dispatch queue on failure. If NULL (default), the main queue is used.

@property (nonatomic, assign) dispatch_queue_t failureCallbackQueue

Discussion

The callback dispatch queue on failure. If NULL (default), the main queue is used.

Declared In

VKHTTPOperation.h

– initWithURLRequest:

Init this operation with URL request

- (instancetype)initWithURLRequest:(NSURLRequest *)urlRequest

Parameters

urlRequest

request to load

Return Value

initialized operation

Discussion

Init this operation with URL request

Declared In

VKHTTPOperation.h

– pause

Pauses the execution of the request operation.

- (void)pause

Discussion

Pauses the execution of the request operation.

A paused operation returns NO for -isReady, -isExecuting, and -isFinished. As such, it will remain in an NSOperationQueue until it is either cancelled or resumed. Pausing a finished, cancelled, or paused operation has no effect.

Declared In

VKHTTPOperation.h

– isPaused

Whether the request operation is currently paused.

- (BOOL)isPaused

Return Value

YES if the operation is currently paused, otherwise NO.

Discussion

Whether the request operation is currently paused.

Declared In

VKHTTPOperation.h

– resume

Resumes the execution of the paused request operation.

- (void)resume

Discussion

Resumes the execution of the paused request operation.

Pause/Resume behavior varies depending on the underlying implementation for the operation class. In its base implementation, resuming a paused requests restarts the original request. However, since HTTP defines a specification for how to request a specific content range, AFHTTPRequestOperation will resume downloading the request from where it left off, instead of restarting the original request.

Declared In

VKHTTPOperation.h

Configuring Backgrounding Task Behavior

– setShouldExecuteAsBackgroundTaskWithExpirationHandler:

Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task.

- (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void ( ^ ) ( void ))handler

Parameters

handler

A handler to be called shortly before the application’s remaining background time reaches 0. The handler is wrapped in a block that cancels the operation, and cleans up and marks the end of execution, unlike the handler parameter in UIApplication -beginBackgroundTaskWithExpirationHandler:, which expects this to be done in the handler itself. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified.

Discussion

Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task.

Declared In

VKHTTPOperation.h

– setUploadProgressBlock:

Sets a callback to be called when an undetermined number of bytes have been uploaded to the server.

- (void)setUploadProgressBlock:(void ( ^ ) ( NSUInteger bytesWritten , long long totalBytesWritten , long long totalBytesExpectedToWrite ))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 three arguments: 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.

Discussion

Sets a callback to be called when an undetermined number of bytes have been uploaded to the server.

Declared In

VKHTTPOperation.h

– setDownloadProgressBlock:

Sets a callback to be called when an undetermined number of bytes have been downloaded from the server.

- (void)setDownloadProgressBlock:(void ( ^ ) ( NSUInteger bytesRead , long long totalBytesRead , long long totalBytesExpectedToRead ))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 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 main thread.

Discussion

Sets a callback to be called when an undetermined number of bytes have been downloaded from the server.

Declared In

VKHTTPOperation.h

– setCompletionBlockWithSuccess:failure:

Sets the completionBlock property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If error returns a value, which can be caused by an unacceptable status code or content type, then failure is executed. Otherwise, success is executed.

- (void)setCompletionBlockWithSuccess:(void ( ^ ) ( VKHTTPOperation *operation , id responseObject ))success failure:(void ( ^ ) ( VKHTTPOperation *operation , NSError *error ))failure

Parameters

success

The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request.

failure

The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request.

Discussion

Sets the completionBlock property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If error returns a value, which can be caused by an unacceptable status code or content type, then failure is executed. Otherwise, success is executed.

This method should be overridden in subclasses in order to specify the response object passed into the success block.

Declared In

VKHTTPOperation.h

Extension Methods

  lock

Operation working lock

@property (readwrite, nonatomic, strong) NSRecursiveLock *lock

Discussion

Operation working lock

Declared In

VKOperation.h