Inherits from NSObject
Declared in MKNetworkEngine.h

Overview

@class MKNetworkEngine @abstract Represents a subclassable Network Engine for your app

@discussion

This class is the heart of MKNetworkEngine

You create network operations and enqueue them here MKNetworkEngine encapsulates a Reachability object that relieves you of managing network connectivity losses MKNetworkEngine also allows you to provide custom header fields that gets appended automatically to every request

Tasks

Properties

reachabilityChangedHandler

@abstract Handler that you implement to monitor reachability changes @property reachabilityChangedHandler

@property (copy, nonatomic) void ( ^ ) ( NetworkStatus ns ) reachabilityChangedHandler

Discussion

@abstract Handler that you implement to monitor reachability changes @property reachabilityChangedHandler

@discussion

The framework calls this handler whenever the reachability of the host changes.

The default implementation freezes the queued operations and stops network activity You normally don’t have to implement this unless you need to show a HUD notifying the user of connectivity loss

Declared In

MKNetworkEngine.h

readonlyHostName

@abstract HostName of the engine @property readonlyHostName

@property (readonly, strong, nonatomic) NSString *readonlyHostName

Discussion

@abstract HostName of the engine @property readonlyHostName

@discussion

Returns the host name of the engine

This property is readonly cannot be updated. You normally initialize an engine with its hostname using the initWithHostName:customHeaders: method

Declared In

MKNetworkEngine.h

Instance Methods

cacheDirectoryName

@abstract Cache Directory Name

- (NSString *)cacheDirectoryName

Discussion

@abstract Cache Directory Name

@discussion

This method can be over-ridden by subclasses to provide an alternative cache directory

The default directory (MKNetworkKitCache) within the NSCaches directory will be used otherwise Overriding this method is optional

Declared In

MKNetworkEngine.h

cacheMemoryCost

@abstract Cache Directory In Memory Cost

- (int)cacheMemoryCost

Discussion

@abstract Cache Directory In Memory Cost

@discussion

This method can be over-ridden by subclasses to provide an alternative in memory cache size.

By default, MKNetworkKit caches 10 recent requests in memory The default size is 10 Overriding this method is optional

Declared In

MKNetworkEngine.h

emptyCache

@abstract Empties previously cached data

- (void)emptyCache

Discussion

@abstract Empties previously cached data

@discussion

This method is a handy helper that you can use to clear cached data.

By default, MKNetworkKit doens’t cache your requests. Use this only when you enabled caching @seealso useCache

Declared In

MKNetworkEngine.h

enqueueOperation:

@abstract Enqueues your operation into the shared queue

- (void)enqueueOperation:(MKNetworkOperation *)request

Discussion

@abstract Enqueues your operation into the shared queue

@discussion

The operation you created is enqueued to the shared queue. If the response for this operation was previously cached, the cached data will be returned.

@seealso enqueueOperation:forceReload:

Declared In

MKNetworkEngine.h

enqueueOperation:forceReload:

@abstract Enqueues your operation into the shared queue.

- (void)enqueueOperation:(MKNetworkOperation *)operation forceReload:(BOOL)forceReload

Discussion

@abstract Enqueues your operation into the shared queue.

@discussion

The operation you created is enqueued to the shared queue. 

When forceReload is NO, this method behaves like enqueueOperation: When forceReload is YES, No cached data will be returned even if cached data is available. @seealso enqueueOperation:

Declared In

MKNetworkEngine.h

imageAtURL:onCompletion:

@abstract Handy helper method for fetching images

- (MKNetworkOperation *)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock)imageFetchedBlock

Discussion

@abstract Handy helper method for fetching images

@discussion

Creates an operation with the given image URL.

The hostname of the engine is NOT prefixed. The image is returned to the caller via MKNKImageBlock callback block.

Declared In

MKNetworkEngine.h

initWithHostName:customHeaderFields:

@abstract Initializes your network engine with a hostname and custom header fields

- (id)initWithHostName:(NSString *)hostName customHeaderFields:(NSDictionary *)headers

Discussion

@abstract Initializes your network engine with a hostname and custom header fields

@discussion

Creates an engine for a given host name

The default headers you specify here will be appened to every operation created in this engine The hostname, if not null, initializes a Reachability notifier. Network reachability notifications are automatically taken care of by MKNetworkEngine Both parameters are optional

Declared In

MKNetworkEngine.h

operationWithPath:

@abstract Creates a simple GET Operation with a request URL

- (MKNetworkOperation *)operationWithPath:(NSString *)path

Discussion

@abstract Creates a simple GET Operation with a request URL

@discussion

Creates an operation with the given URL path.

The default headers you specified in your MKNetworkEngine subclass gets added to the headers The HTTP Method is implicitly assumed to be GET

Declared In

MKNetworkEngine.h

operationWithPath:params:

@abstract Creates a simple GET Operation with a request URL and parameters

- (MKNetworkOperation *)operationWithPath:(NSString *)path params:(NSMutableDictionary *)body

Discussion

@abstract Creates a simple GET Operation with a request URL and parameters

@discussion

Creates an operation with the given URL path.

The default headers you specified in your MKNetworkEngine subclass gets added to the headers The body dictionary in this method gets attached to the URL as query parameters The HTTP Method is implicitly assumed to be GET

Declared In

MKNetworkEngine.h

operationWithPath:params:httpMethod:

@abstract Creates a simple GET Operation with a request URL, parameters and HTTP Method

- (MKNetworkOperation *)operationWithPath:(NSString *)path params:(NSMutableDictionary *)body httpMethod:(NSString *)method

Discussion

@abstract Creates a simple GET Operation with a request URL, parameters and HTTP Method

@discussion

Creates an operation with the given URL path.

The default headers you specified in your MKNetworkEngine subclass gets added to the headers The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE The params dictionary is attached to the body if the HTTP Method is POST/PUT The HTTP Method is implicitly assumed to be GET

Declared In

MKNetworkEngine.h

operationWithPath:params:httpMethod:ssl:

@abstract Creates a simple GET Operation with a request URL, parameters, HTTP Method and the SSL switch

- (MKNetworkOperation *)operationWithPath:(NSString *)path params:(NSMutableDictionary *)body httpMethod:(NSString *)method ssl:(BOOL)useSSL

Discussion

@abstract Creates a simple GET Operation with a request URL, parameters, HTTP Method and the SSL switch

@discussion

Creates an operation with the given URL path.

The ssl option when true changes the URL to https. The ssl option when false changes the URL to http. The default headers you specified in your MKNetworkEngine subclass gets added to the headers The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE The params dictionary is attached to the body if the HTTP Method is POST/PUT The previously mentioned methods operationWithPath: and operationWithPath:params: call this internally

Declared In

MKNetworkEngine.h

operationWithURLString:

@abstract Creates a simple GET Operation with a request URL

- (MKNetworkOperation *)operationWithURLString:(NSString *)urlString

Discussion

@abstract Creates a simple GET Operation with a request URL

@discussion

Creates an operation with the given absolute URL.

The hostname of the engine is NOT prefixed The default headers you specified in your MKNetworkEngine subclass gets added to the headers The HTTP method is implicitly assumed to be GET.

Declared In

MKNetworkEngine.h

operationWithURLString:params:

@abstract Creates a simple GET Operation with a request URL and parameters

- (MKNetworkOperation *)operationWithURLString:(NSString *)urlString params:(NSMutableDictionary *)body

Discussion

@abstract Creates a simple GET Operation with a request URL and parameters

@discussion

Creates an operation with the given absolute URL.

The hostname of the engine is NOT prefixed The default headers you specified in your MKNetworkEngine subclass gets added to the headers The body dictionary in this method gets attached to the URL as query parameters The HTTP method is implicitly assumed to be GET.

Declared In

MKNetworkEngine.h

operationWithURLString:params:httpMethod:

@abstract Creates a simple Operation with a request URL, parameters and HTTP Method

- (MKNetworkOperation *)operationWithURLString:(NSString *)urlString params:(NSMutableDictionary *)body httpMethod:(NSString *)method

Discussion

@abstract Creates a simple Operation with a request URL, parameters and HTTP Method

@discussion

Creates an operation with the given absolute URL.

The hostname of the engine is NOT prefixed The default headers you specified in your MKNetworkEngine subclass gets added to the headers The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE The params dictionary is attached to the body if the HTTP Method is POST/PUT

This method can be over-ridden by subclasses to tweak the operation creation mechanism.

You would typically over-ride this method to create a subclass of MKNetworkOperation (if you have one). After you create it, you should call [super prepareHeaders:operation] to attach any custom headers from super class. @seealso prepareHeaders:

Declared In

MKNetworkEngine.h

prepareHeaders:

@abstract adds the custom default headers

- (void)prepareHeaders:(MKNetworkOperation *)operation

Discussion

@abstract adds the custom default headers

@discussion

This method adds custom default headers to the factory created MKNetworkOperation.
This method can be over-ridden by subclasses to add more default headers if necessary.

You would typically over-ride this method if you have over-ridden operationWithURLString:params:httpMethod:. @seealso operationWithURLString:params:httpMethod:

Declared In

MKNetworkEngine.h

registerOperationSubclass:

@abstract Registers an associated operation subclass

- (void)registerOperationSubclass:(Class)aClass

Discussion

@abstract Registers an associated operation subclass

@discussion

When you override both MKNetworkEngine and MKNetworkOperation, you might want the engine's factory method

to prepare operations of your MKNetworkOperation subclass. To create your own MKNetworkOperation subclasses from the factory method, you can register your MKNetworkOperation subclass using this method. This method is optional. If you don’t use, factory methods in MKNetworkEngine creates MKNetworkOperation objects.

Declared In

MKNetworkEngine.h

useCache

@abstract Enable Caching

- (void)useCache

Discussion

@abstract Enable Caching

@discussion

This method should be called explicitly to enable caching for this engine.

By default, MKNetworkKit doens’t cache your requests. The cacheMemoryCost and cacheDirectoryName will be used when you turn caching on using this method.

Declared In

MKNetworkEngine.h