A progressive download operation for AFNetworking.
Pull request Compare This branch is 60 commits behind steipete:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
AFDownloadRequestOperation.h
AFDownloadRequestOperation.m
LICENCE
README.md

README.md

AFDownloadRequestOperation

A progressive download operation for AFNetworking. I wrote this to support large PDF downloads in my iOS PDF framework PSPDFKit, but it works for any file type.

While AFNetworking already supports downloading files, this class has additional support to resume a partial download, uses a temporary directory and has a special block that helps with calculating the correct download progress.

AFDownloadRequestOperation is smart with choosing the correct targetPath. If you set a folder, the file name of the downloaded URL will be used, else the file name that is already set.

AFDownloadRequestOperation also relays any NSError that happened during a file operation to the faulure block.

With partially resumed files, the progress delegate needs additional info. The server might only have a few totalByesExpected, but we wanna show the correct value that includes the previous progress.

    [pdfRequest setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
        self.downloadProgress = totalBytesReadForFile/(float)totalBytesExpectedToReadForFile;
    }];

The temporary folder will be automatically created on first access, but an be changed. It defaults to <app directory>tmp/Incomplete/. The temp directory will be cleaned by the system on a regular bases; so a resume will only succeed if there's not much time between.

AFNetworking

This is tested against the latest AFNetworking branch (experimental-1.0RC2) and uses ARC.

Creator

Peter Steinberger @steipete

License

AFDownloadRequestOperation is available under the MIT license. See the LICENSE file for more info.