Ext.: http://zyc-to.blog.163.com/blog/static/17152400201110221114526/
Starting with version 0.94, ASIHTTPRequest can resume interrupted downloads
12345678910111213141516171819 |
- (
IBAction
)resumeInterruptedDownload:(
id
)sender
{
NSURL
*url = [
NSURL
URLWithString
:
@
"http://www.dreamingwish.com/wp-content/uploads/2011/10/asihttprequest-auth.png"
];
ASIHTTPRequest *request = [ASIHTTPRequest
requestWithURL
:url];
NSString
*downloadPath =
@
"/Users/ben/Desktop/asi.png"
;
//当request完成时,整个文件会被移动到这里
[request
setDownloadDestinationPath
:downloadPath];
//这个文件已经被下载了一部分
[request
setTemporaryFileDownloadPath
:
@
"/Users/ben/Desktop/asi.png.download"
];
[request
setAllowResumeForFileDownloads
:
YES
];
[request
startSynchronous
];
//整个文件将会在这里
NSString
*theContent = [
NSString stringWithContentsOfFile
:downloadPath];
}
|
This feature is only valid for downloading data to a file, you must set allowresumeforfiledownloads to Yes for the request of the situation:
- Any download that you would like to be able to resume in the future (otherwise, ASIHTTPRequest will delete the temporary file when the memory is canceled or freed)
- Any download you want to continue with the breakpoint
In addition, you must set a temporary download path (settemporaryfiledownloadpath), which is the path to the incomplete data. The new data will be added to this file, and when the download is complete, the file will be moved to Downloaddestinationpath .
The continuation of the breakpoint works by reading the size of the Temporaryfiledownloadpath file and using the range:bytes=x HTTP header to request the remaining file contents.
ASIHTTPRequest does not detect the presence of a accept-ranges header (because additional head-header requests consume additional resources), so this feature is used only if the server is determined to support the continuation of a breakpoint download.
Asihttprequest-Breakpoint continued to need the original site support!