iOS开发ASIHttpRequest介绍(七)-- ASIHTTPRequest断点续传(下载)
来源:互联网 发布:mysql 5.5 for mac 编辑:程序博客网 时间:2024/05/16 05:49
本文为大家介绍了iOS开发ASIHTTPRequest断点续传(下载)的内容,其中包括ASIHTTPRequest可以恢复中断的下载,设置一个临时下载路径,断点续传的工作原理等等内容。
从0.94版本开始,ASIHTTPRequest可以恢复中断的下载。
这个特性只对下载数据到文件中有效,你必须为一下情况的request设置allowResumeForFileDownloads 为YES:
- 任何你希望将来可以断点续传的下载(否则,ASIHTTPRequest会在取消或者释放内存时将临时文件删除)
- 任何你要进行断点续传的下载
另外,你必须自己设置一个临时下载路径(setTemporaryFileDownloadPath),这个路径是未完成的数据的路径。新的数据将会被添加到这个文件,当下载完成时,这个文件将被移动到downloadDestinationPath 。
- - (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];
- }
断点续传的工作原理是读取temporaryFileDownloadPath的文件的大小,并使用Range: bytes=x HTTP头来请求剩余的文件内容。
ASIHTTPRequest并不检测是否存在Accept-Ranges头(因为额外的HEAD头请求会消耗额外的资源),所以只有确定服务器支持断点续传下载时,再使用这个特性。
0 0
- iOS开发ASIHttpRequest介绍(七)-- ASIHTTPRequest断点续传(下载)
- iOS开发ASIHttpRequest介绍(七)-- ASIHTTPRequest断点续传(下载)
- iOS开发ASIHTTPRequest断点续传(下载)
- iOS开发ASIHTTPRequest断点续传(下载)
- iOS开发ASIHTTPRequest断点续传(下载)【8】
- iOS开发ASIHTTPRequest断点续传
- ASIHTTPRequest-断点续传(下载)
- ASIHTTPRequest-断点续传(下载)
- ASIHTTPRequest-断点续传(下载)
- ASIHTTPRequest-断点续传(下载)
- ASIHTTPRequest-断点续传(下载)
- ASIHTTPRequest-断点续传(下载)
- iOS开发asi使用(五)ASIHTTPRequest断点续传(下载)
- iOS开发ASIHttpRequest介绍(二)-- ASIHttpRequest发送数据
- iOS开发ASIHttpRequest介绍(三)-- ASIHTTPRequest进度追踪
- iOS开发ASIHttpRequest介绍(四)--ASIHTTPRequest身份验证
- iOS开发ASIHttpRequest介绍(六)-- ASIHTTPRequest数据压缩
- iOS开发ASIHttpRequest介绍(九)-- ASIHTTPRequest使用download cache
- 电脑知识硬件普及
- Choose a destination with a supported architecture in order to run on this device.
- 美食菜谱将会成创业风口的两大理由
- mysql进入命令
- 用java实现邮件服务的几种方式总结
- iOS开发ASIHttpRequest介绍(七)-- ASIHTTPRequest断点续传(下载)
- Android的UAProfe和UA String
- can总线的示波器检测方法
- POJ-1003-HangOver
- 巧用“Windows 7媒体中心”欣赏图片文件
- MutiBytes To UTF8
- 一个题目,涉及结构体数组的初始化与输出
- 成都美女董事长何燕被批捕 涉足北斗导航产业
- Android开发和iOS的相同与不同