SBBNetworkManagerProtocol Protocol Reference

Conforms to NSObject
Declared in SBBNetworkManager.h

Overview

This protocol defines the interface to the SBBNetworkManager’s non-constructor, non-initializer methods. The interface is abstracted out for use in mock objects for testing, and to allow selecting among multiple implementations at runtime.

  sendCookies required method

This property tells the network manager whether it should send cookies with its requests.

@property (nonatomic, assign) BOOL sendCookies

Discussion

For network managers communicating with Bridge servers, this should be set to NO. Otherwise defaults to YES.

Declared In

SBBNetworkManager.h

– get:headers:parameters:background:completion: required method

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

– get:headers:parameters:completion: required method

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

– post:headers:parameters:background:completion: required method

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

– post:headers:parameters:completion: required method

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

– put:headers:parameters:background:completion: required method

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

– put:headers:parameters:completion: required method

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

– delete:headers:parameters:background:completion: required method

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

– delete:headers:parameters:completion: required method

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

– uploadFile:httpHeaders:toUrl:taskDescription:completion: required method

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: required method

- (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: required method

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