在工程中,我们会常常遇到需要下载的程序,比如下载在线音乐、下载图片等等,今天我将介绍一下利用ASIHTTPRequest的下载示例,支持断点续传,利用ASIHTTPRequest下载以及断点续传的原理,今天重点介绍如何实现,废话少说,开始正文:
一、创建网络请求队列
首先,创建网络请求队列,如下:
二、创建存放路径
三、发送下载请求
这里对下面几个对象说明一下:CustomCell是我自定义的cell,cell上面有下载和暂停两个按钮,其tag值为cell所在的行,因此这里的[sendertag]为下载按钮的tag值,self.downloadArray为array数组对象,存放要下载的资源字典信息,在该字典中有一键为URL,它对应的值就是我们下载链接。
这些东西,根据自己的实际需要改动一下即可使用
三、暂停请求
这里的cell下下载时的一样,
四、ASIHTTPRequestDelegate回调方法
上面已经把下载请求与暂停请求实现,点击下载时,开始下载资源;当点暂停时,下载中断;当我们再点击下载按钮时,继续下载,在第二步的
[request setAllowResumeForFileDownloads:YES]设置是是否支持断点下载。下面要实现ASIHTTPRequestDelegate代理方法如下:
一、创建网络请求队列
首先,创建网络请求队列,如下:
二、创建存放路径
三、发送下载请求
这里对下面几个对象说明一下:CustomCell是我自定义的cell,cell上面有下载和暂停两个按钮,其tag值为cell所在的行,因此这里的[sendertag]为下载按钮的tag值,self.downloadArray为array数组对象,存放要下载的资源字典信息,在该字典中有一键为URL,它对应的值就是我们下载链接。
这些东西,根据自己的实际需要改动一下即可使用
三、暂停请求
这里的cell下下载时的一样,
四、ASIHTTPRequestDelegate回调方法
上面已经把下载请求与暂停请求实现,点击下载时,开始下载资源;当点暂停时,下载中断;当我们再点击下载按钮时,继续下载,在第二步的
[request setAllowResumeForFileDownloads:YES]设置是是否支持断点下载。下面要实现ASIHTTPRequestDelegate代理方法如下: