Inherits from NSObject
Declared in TCBlobDownloadManager.h

Overview

TCBlobDownloadManager is a subclass of NSOperationQueue and is used to execute TCBlobDownloader objects.

It provides methods to start and cancel a download, as well as defining a maximum amount of simultaneous downloads.

Note

This class should be used as a singleton using the sharedInstance method.

Properties

currentDownloadsCount

The number of downloads currently being executed by the queue (currently downloading data).

@property (nonatomic, assign) NSUInteger currentDownloadsCount

Availability

1.6.0

Declared In

TCBlobDownloadManager.h

defaultDownloadPath

The default download path for a file if no customPath property is set at the creation of the TCBlobDownloader object.

@property (nonatomic, copy) NSString *defaultDownloadPath

Availability

1.1

Discussion

The default value is /tmp.

Warning: Please be careful of the iOS Data Storage Guidelines when setting the download path.

Declared In

TCBlobDownloadManager.h

downloadCount

The number of downloads currently in the queue

@property (nonatomic, assign) NSUInteger downloadCount

Availability

1.0

Declared In

TCBlobDownloadManager.h

Class Methods

sharedInstance

Creates and returns a TCBlobDownloadManager object. If the singleton has already been created, it just returns the object.

+ (instancetype)sharedInstance

Availability

1.5.0

Declared In

TCBlobDownloadManager.h

Instance Methods

cancelAllDownloadsAndRemoveFiles:

Cancels all downloads. Remove already downloaded parts of the files from the disk is asked.

- (void)cancelAllDownloadsAndRemoveFiles:(BOOL)remove

Parameters

remove

If YES, this method will remove all downloaded files parts from the disk. Files parts are left untouched if set to NO. This will allow TCBlobDownload to restart the download from where it has ended in a future operation.

Availability

1.0

Declared In

TCBlobDownloadManager.h

setDefaultDownloadPath:error:

Specifies the default download path. (which is /tmp by default)

- (BOOL)setDefaultDownloadPath:(NSString *)pathToDL error:(NSError *__autoreleasing *)error

Parameters

pathToDL

The new default path. @param error

Return Value

A boolean that is the result of [NSFileManager createDirFromPath:error:]

Availability

1.1

Discussion

The path can be non existant, if so, it will be created.

Declared In

TCBlobDownloadManager.h

setMaxConcurrentDownloads:

Set the maximum number of concurrent downloads allowed. If more downloads are passed to the TCBlobDownloadManager singleton, they will wait for an older one to end before starting.

- (void)setMaxConcurrentDownloads:(NSInteger)max

Parameters

max

The maximum number of downloads.

Availability

1.0

Declared In

TCBlobDownloadManager.h

setOperationQueueName:

Name the underlying NSOperationQueue

- (void)setOperationQueueName:(NSString *)name

Parameters

name

Name to give to the NSOperationQueue

Availability

2.1.0

Declared In

TCBlobDownloadManager.h

startDownload:

Starts an already instanciated TCBlobDownloader object.

- (void)startDownload:(TCBlobDownloader *)download

Parameters

download

A TCBlobDownloader object.

Availability

1.0

Discussion

You can instanciate a TCBlobDownloader object and instead of executing it directly using startDownloadWithURL:customPath:delegate: or the block equivalent, pass it to this method whenever you’re ready.

Declared In

TCBlobDownloadManager.h

startDownloadWithURL:customPath:delegate:

Instanciates and runs instantly a TCBlobDownloadObject with the specified URL, an optional customPath and an optional delegate. Runs in background thread the TCBlobDownloader object (a subclass of NSOperation) in the TCBlobDownloadManager instance.

- (TCBlobDownloader *)startDownloadWithURL:(NSURL *)url customPath:(NSString *)customPathOrNil delegate:(id<TCBlobDownloaderDelegate>)delegateOrNil

Parameters

url

The URL of the file to download.

customPathOrNil

An optional path to override the default download path of the TCBlobDownloadManager instance. Can be nil.

delegateOrNil

An optional delegate. Can be nil.

Return Value

The created and already running TCBlobDownloadObject.

Availability

1.4

Discussion

This method returns the created TCBlobDownloader object for further use.

Declared In

TCBlobDownloadManager.h

startDownloadWithURL:customPath:firstResponse:progress:error:complete:

Instanciates and runs instantly a TCBlobDownloader object. Provides the same functionnalities than startDownloadWithURL:customPath:delegate: but creates a TCBlobDownloadObject using blocks to update your view.

- (TCBlobDownloader *)startDownloadWithURL:(NSURL *)url customPath:(NSString *)customPathOrNil firstResponse:(void ( ^ ) ( NSURLResponse *response ))firstResponseBlock progress:(void ( ^ ) ( uint64_t receivedLength , uint64_t totalLength , NSInteger remainingTime , float progress ))progressBlock error:(void ( ^ ) ( NSError *error ))errorBlock complete:(void ( ^ ) ( BOOL downloadFinished , NSString *pathToFile ))completeBlock

Parameters

url

The URL of the file to download.

customPathOrNil

An optional path to override the default download path of the TCBlobDownloadManager instance. Can be nil.

firstResponseBlock

This block is called when receiving the first response from the server. Can be nil.

progressBlock

This block is called on each response from the server while the download is occurring. Can be nil. If the remaining time has not been calculated yet, the value is -1. @param errorBlock Called when an error occur during the download. If this block is called, the download will be cancelled just after. Can be nil.

completeBlock

Called when the download is completed or cancelled. Can be nil. If the download has been cancelled with the paramater removeFile set to YES, then the pathToFile parameter is nil. The TCBlobDownloader operation will be removed from TCBlobDownloadManager just after this block is called.

Availability

1.4

See Also

Declared In

TCBlobDownloadManager.h