SBBUploadManagerProtocol Protocol Reference

Conforms to SBBBridgeAPIManagerProtocol
Declared in SBBUploadManager.h

Overview

This protocol defines the interface to the SBBUploadManager’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.

  uploadDelegate required method

Set this property to set an upload delegate to be notified when a background upload completes (or fails), even if it happens after the app has been relaunched. Note that if the user swipes the app out of the app switcher screen, all current uploads will have been canceled anyway and the uploadDelegate won’t get called.

@property (nonatomic, weak) id<SBBUploadManagerDelegate> uploadDelegate

Discussion

To ensure that your delegate gets called, you should set this property in your AppDelegate’s application:didFinishLaunchingWithOptions: and application:handleEventsForBackgroundURLSession:completionHandler: methods.

Declared In

SBBUploadManager.h

– uploadFileToBridge:contentType:completion: required method

Upload a file to the Bridge server on behalf of the authenticated user, via the NSURLSessionUploadTask so it can proceed even if the app is suspended or killed. Requesting the pre-signed URL for the upload from the Bridge API happens in a background download task so that the whole process can be initiated regardless of current network connectivity, and will proceed as and when possible.

- (void)uploadFileToBridge:(NSURL *)fileUrl contentType:(NSString *)contentType completion:(SBBUploadManagerCompletionBlock)completion

Parameters

fileUrl

The file to upload.

contentType

The MIME type of the file (defaults to “application/octet-stream” if nil).

completion

A completion block to be called when the upload finishes (or fails). Note that this will never be called if the app has to be relaunched to respond to the background session delegate events; blocks cannot be persisted across app launches. If you need to be sure to get the call upon completion (successful or otherwise), set an uploadDelegate.

Discussion

The file is copied to a temporary file with a unique name in the temporary directory, and the copy is uploaded, so the original can be safely deleted any time after making this call (though you may want to wait and do it in the uploadManager:uploadOfFile:completedWithError: method, in case the upload fails so you can try again). The temporary copy is deleted upon successful or unsuccessful completion of the upload attempt.

Declared In

SBBUploadManager.h

– uploadFileToBridge:completion: required method

This is a convenience method that determines the appropriate content-type based on the file extension and calls through to uploadFileToBridge:contentType:completion:.

- (void)uploadFileToBridge:(NSURL *)fileUrl completion:(SBBUploadManagerCompletionBlock)completion

Declared In

SBBUploadManager.h