TCBlobDownloader Class Reference
Inherits from | NSOperation |
Conforms to | NSURLConnectionDelegate |
Declared in | TCBlobDownloader.h |
Overview
TCBlobDownloader
is a subclass of Cocoa’s NSOperation
. It’s purpose is to be executed by the TCBlobDownloaderManager
singleton to download large files in background threads.
Each TCBlobDownloader
instance will run in a background thread and will download files via an NSURLConnection
. Each TCBlobDownloader
can depend (or not) of a TCBlobDownloaderDelegate
or use blocks to notify your UI from its status.
Tasks
-
delegate
property -
pathToDownloadDirectory
property -
pathToFile
property -
downloadURL
property -
fileRequest
property -
fileName
property -
speedRate
property -
remainingTime
property -
progress
property -
state
property -
– initWithURL:downloadPath:delegate:
-
– initWithURL:downloadPath:firstResponse:progress:error:complete:
-
– cancelDownloadAndRemoveFile:
-
– addDependentDownload:
Properties
delegate
The delegate property of a TCBlobDownloader
instance. Can be nil
.
@property (nonatomic, unsafe_unretained) id<TCBlobDownloaderDelegate> delegate
Availability
1.0
Declared In
TCBlobDownloader.h
downloadURL
The URL of the file to download.
@property (nonatomic, copy, readonly) NSURL *downloadURL
Availability
1.0
Discussion
Warning: You should not set this property directly, as it is managed by the initialization method.
Declared In
TCBlobDownloader.h
fileName
If not manually set, the file name, which is by default based on the last path component of the download URL.
@property (nonatomic, copy, getter=fileName) NSString *fileName
Availability
1.0
Discussion
Note
You should not change the file name during the download process. The file name of a file downloaded by TCBlobDownload is the last part of the URL used to download it. This allow TCBlobDownload to check if a part of that file has already been downloaded and if so, retrieve the downloaded from where it has previously stopped. It is up to you to manage your download paths to avoid downloading 2 files with the same name.
You can change the file name once the file has been downloaded in the completion block or the appropriate delegate method.
Warning: It is not recommended to set this property directly, as it is retrieved from the download URL and will allow you to resume a download from where it stopped.
See Also
TCBlobDownloaderDelegate protocol
Declared In
TCBlobDownloader.h
fileRequest
The NSMutableURLRequest that will be performed by the NSURLConnection. Use this object to pass custom headers to your request if needed.
@property (nonatomic, strong, readonly) NSMutableURLRequest *fileRequest
Availability
1.6.0
Declared In
TCBlobDownloader.h
pathToDownloadDirectory
The directory where the file is being downloaded.
@property (nonatomic, copy, readonly) NSString *pathToDownloadDirectory
Availability
1.0
Declared In
TCBlobDownloader.h
pathToFile
The path to the downloaded file, including the file name.
@property (nonatomic, copy, readonly, getter=pathToFile) NSString *pathToFile
Availability
1.0
Discussion
Warning: You should not set this property directly as the file name is managed by the library.
Declared In
TCBlobDownloader.h
progress
Current progress of the download.
@property (nonatomic, assign, readonly, getter=progress) float progress
Discussion
Value between 0 and 1
Declared In
TCBlobDownloader.h
remainingTime
The estimated number of seconds before the download completes.
@property (nonatomic, assign, readonly, getter=remainingTime) NSInteger remainingTime
Availability
1.5.0
Discussion
-1
if the remaining time has not been calculated yet.
Declared In
TCBlobDownloader.h
Instance Methods
addDependentDownload:
Makes the receiver download dependent of the given download. The receiver download will not execute itself until the given download has finished.
- (void)addDependentDownload:(TCBlobDownloader *)download
Parameters
- download
The TCBlobDownloader on which to depend.
Availability
1.2
Declared In
TCBlobDownloader.h
cancelDownloadAndRemoveFile:
Cancels the download. Remove already downloaded parts of the file from the disk is asked.
- (void)cancelDownloadAndRemoveFile:(BOOL)remove
Parameters
- remove
If
YES
, this method will remove the downloaded file parts from the disk. File parts are left untouched if set toNO
. This will allow TCBlobDownload to restart the download from where it has ended in a future operation.
Availability
1.0
Declared In
TCBlobDownloader.h
initWithURL:downloadPath:delegate:
Instanciates a TCBlobDownloader
object with delegate. TCBlobDownloader
objects instanciated this way will not be executed until they are passed to the TCBlobDownloaderManager
singleton.
- (instancetype)initWithURL:(NSURL *)url downloadPath:(NSString *)pathToDL delegate:(id<TCBlobDownloaderDelegate>)delegateOrNil
Parameters
- url
The URL from where to download the file.
- delegateOrNil
An optional delegate. Can be
nil
.
- pathToDLOrNil
An optional path to override the default download path of the
TCBlobDownloaderManager
instance. Can benil
.
Return Value
The newly created TCBlobDownloader
.
Availability
1.0
Declared In
TCBlobDownloader.h
initWithURL:downloadPath:firstResponse:progress:error:complete:
Instanciates a TCBlobDownloader
object with response blocks. TCBlobDownloader
objects instanciated this way will not be executed until they are passed to the TCBlobDownloaderManager
singleton.
- (instancetype)initWithURL:(NSURL *)url downloadPath:(NSString *)pathToDL 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.
- 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
.
- 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 paramaterremoveFile
set toYES
, then thepathToFile
parameter isnil
. TheTCBlobDownloader
operation will be removed fromTCBlobDownloadManager
just after this block is called.
- customPathOrNil
An optional path to override the default download path of the
TCBlobDownloaderManager
instance. Can benil
.
Return Value
The newly created TCBlobDownloader
.
Availability
1.3
Declared In
TCBlobDownloader.h