ios ASI 断点下载

mac2022-06-30  18

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

//1.创建请求对象 NSURL *url=[NSURL URLWithString:@"在这里输入你的下载链接"]; ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url]; //2.设置下载文件保存的路径 NSString *cachepath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)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];

转载于:https://www.cnblogs.com/JJFly/p/4297756.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)