ASI断点下载

来源:互联网 发布:java手机游戏 编辑:程序博客网 时间:2024/06/11 14:54

ASI的断点下载技术非常的好用, 任何有下载功能的应用都可以试试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//1.创建请求对象
     NSURL *url=[NSURL URLWithString:@"在这里输入你的下载链接"];
     ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
      
     //2.设置下载文件保存的路径
     NSString *cachepath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES)lastObject];
     NSString *filename=[cachepath stringByAppendingPathComponent:@"video.zip"];
     request.downloadDestinationPath=filename;
     NSLog(@"%@",filename);
      
     //3.设置下载进度的代理
     request.downloadProgressDelegate=self.progress; // 这里别忘了签代理<ASIProgressDelegate>
      
     //4.发送网络请求(异步)
     [request startAsynchronous];
 
    // 5.断点下载:
     request.allowResumeForFileDownloads=YES;
 
     //6.下载完毕后通知
     [request setCompletionBlock:^{
         NSLog(@"文件已经下载完毕");
     }];

取消下载方法:

[request clearDelegatesAndCancel];

0 0
原创粉丝点击