SBBNetworkManager Class Reference

Inherits from NSObject
Conforms to SBBComponent
SBBNetworkManagerProtocol
Declared in SBBNetworkManager.h
SBBNetworkManager.m

Overview

This class handles HTTP networking with the Bridge REST API.

Other Methods

– initWithBaseURL:

If you want to use SBBNetworkManager’s features to access a different REST API, you can create an instance using this initializer, with the scheme and host part of that API’s URL as the baseURL.

- (instancetype)initWithBaseURL:(NSString *)baseURL

Parameters

baseURL

The scheme and host part of a third-party REST API, e.g. https://webapi.somecompany.com . The urlString parameter of the put, get, etc. methods could then either be the fully-qualified URL of the endpoint you are accessing, or just the path part.

Return Value

An initialized SBBNetworkManager instance with the given baseURL.

Declared In

SBBNetworkManager.h

Other Methods

– get:headers:parameters:completion:

This is a convenience method that assumes a default value of NO for background.

- (NSURLSessionTask *)get:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters completion:(SBBNetworkManagerCompletionBlock)completion

Declared In

SBBNetworkManager.h

– get:headers:parameters:background:completion:

Perform an HTTP GET with the specified URL, HTTP headers, parameters, and completion handler.

- (NSURLSessionTask *)get:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters background:(BOOL)background completion:(SBBNetworkManagerCompletionBlock)completion

Parameters

URLString

The URL to which you are making this HTTP request.

headers

The HTTP headers for this request.

parameters

The parameters for this request, to be passed in the query portion of the request.

background

A BOOL flag indicating whether the request should be performed as a background download.

completion

A block to be executed on completion of the request (successful or otherwise), of type SBBNetworkManagerCompletionBlock.

Return Value

The NSURLSessionTask used to make the request, so you can cancel or suspend/resume the request.

Declared In

SBBNetworkManager.h

– put:headers:parameters:completion:

This is a convenience method that assumes a default value of NO for background.

- (NSURLSessionTask *)put:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters completion:(SBBNetworkManagerCompletionBlock)completion

Declared In

SBBNetworkManager.h

– put:headers:parameters:background:completion:

Perform an HTTP PUT with the specified URL, HTTP headers, parameters, and completion handler.

- (NSURLSessionTask *)put:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters background:(BOOL)background completion:(SBBNetworkManagerCompletionBlock)completion

Parameters

URLString

The URL to which you are making this HTTP request.

headers

The HTTP headers for this request.

parameters

The parameters for this request, to be passed in the request body as JSON. May be nil.

background

A BOOL flag indicating whether the request should be performed as a background download.

completion

A block to be executed on completion of the request (successful or otherwise), of type SBBNetworkManagerCompletionBlock.

Return Value

The NSURLSessionTask used to make the request, so you can cancel or suspend/resume the request.

Declared In

SBBNetworkManager.h

– post:headers:parameters:completion:

This is a convenience method that assumes a default value of NO for background.

- (NSURLSessionTask *)post:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters completion:(SBBNetworkManagerCompletionBlock)completion

Declared In

SBBNetworkManager.h

– post:headers:parameters:background:completion:

Perform an HTTP POST with the specified URL, HTTP headers, parameters, and completion handler.

- (NSURLSessionTask *)post:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters background:(BOOL)background completion:(SBBNetworkManagerCompletionBlock)completion

Parameters

URLString

The URL to which you are making this HTTP request.

headers

The HTTP headers for this request.

parameters

The parameters for this request, to be passed in the request body as JSON. May be nil.

background

A BOOL flag indicating whether the request should be performed as a background download.

completion

A block to be executed on completion of the request (successful or otherwise), of type SBBNetworkManagerCompletionBlock.

Return Value

The NSURLSessionTask used to make the request, so you can cancel or suspend/resume the request.

Declared In

SBBNetworkManager.h

– delete:headers:parameters:completion:

This is a convenience method that assumes a default value of NO for background.

- (NSURLSessionTask *)delete:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters completion:(SBBNetworkManagerCompletionBlock)completion

Discussion

Note: Since delete is a C++ keyword, when calling this method from Objective-C++ you must use the selector delete_:headers:parameters:completion: instead of delete:headers:parameters:completion:.

Declared In

SBBNetworkManager.h

– delete:headers:parameters:background:completion:

Perform an HTTP DELETE with the specified URL, HTTP headers, parameters, and completion handler.

- (NSURLSessionTask *)delete:(NSString *)URLString headers:(NSDictionary *)headers parameters:(id)parameters background:(BOOL)background completion:(SBBNetworkManagerCompletionBlock)completion

Parameters

URLString

The URL to which you are making this HTTP request.

headers

The HTTP headers for this request.

parameters

The parameters for this request, to be passed in the request body as JSON. Usually for a DELETE this will be nil.

background

A BOOL flag indicating whether the request should be performed as a background download.

completion

A block to be executed on completion of the request (successful or otherwise), of type SBBNetworkManagerCompletionBlock.

Return Value

The NSURLSessionTask used to make the request, so you can cancel or suspend/resume the request.

Discussion

Note: Since delete is a C++ keyword, when calling this method from Objective-C++ you must use the selector delete_:headers:parameters:background:completion: instead of delete:headers:parameters:background:completion:.

Declared In

SBBNetworkManager.h

– uploadFile:httpHeaders:toUrl:taskDescription:completion:

Perform a background upload of a file to a given URL with provided HTTP headers.

- (NSURLSessionUploadTask *)uploadFile:(NSURL *)fileUrl httpHeaders:(NSDictionary *)headers toUrl:(NSString *)urlString taskDescription:(NSString *)description completion:(SBBNetworkManagerTaskCompletionBlock)completion

Parameters

fileUrl

The URL of the file to be uploaded.

headers

An NSDictionary containing the HTTP headers as key-value pairs.

urlString

The URL (as a string) to which to upload the file.

description

A string to associate with this task.

completion

SBBNetworkManagerTaskCompletionBlock to be called upon completion of the upload.

Return Value

The NSURLSessionUploadTask used to make the request, so you can cancel or suspend/resume the request.

Declared In

SBBNetworkManager.h

– downloadFileFromURLString:method:httpHeaders:parameters:taskDescription:downloadCompletion:taskCompletion:

- (NSURLSessionDownloadTask *)downloadFileFromURLString:(NSString *)urlString method:(NSString *)httpMethod httpHeaders:(NSDictionary *)headers parameters:(NSDictionary *)parameters taskDescription:(NSString *)description downloadCompletion:(SBBNetworkManagerDownloadCompletionBlock)downloadCompletion taskCompletion:(SBBNetworkManagerTaskCompletionBlock)taskCompletion

Declared In

SBBNetworkManager.h

– restoreBackgroundSession:completionHandler:

This method should be called from your app delegate’s application:handleEventsForBackgroundURLSession:completionHandler: method when the identifier passed in there matches kBackgroundSessionIdentifier.

- (void)restoreBackgroundSession:(NSString *)identifier completionHandler:(void ( ^ ) ( void ))completionHandler

Parameters

identifier

The session identifier, as passed in to your app delegate’s application:handleEventsForBackgroundURLSession:completionHandler: method.

completionHandler

The completion handler, as passed in to your app delegate’s application:handleEventsForBackgroundURLSession:completionHandler: method.

Discussion

If you are setting up and registering your own custom NetworkManager instance rather than using one of the BridgeSDK’s +setupWithAppPrefix: methods, you will also need to call this from your app delegate’s application:didFinishLaunchingWithOptions: method with kBackgroundSessionIdentifier as the identifier, and nil for the completion handler.

Declared In

SBBNetworkManager.h