文件下载
#import "SNViewController.h"
#import "ASIHTTPRequest.h"
@interface SNViewController ()
@property(nonatomic, strong) ASIHTTPRequest *request;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@end
@implementation SNViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self download];
}
-(void)download
{
//1.创建请求对象
NSURL *url = [NSURL URLWithString:@"http://update.55115511.cn/android/suizb/szb.apk"];
self.request = [ASIHTTPRequest requestWithURL:url];
//2.设置所下载的文件保存路径
NSString *cache = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
NSString *filepath = [cache stringByAppendingPathComponent:@"szb.apk"];
NSLog(@"%@", filepath);
self.request.downloadDestinationPath = filepath;
//3.设置下载代理
self.request.downloadProgressDelegate = self.progressView;
//4.支持断点下载
self.request.allowResumeForFileDownloads = YES;
//5.发送下载请求
[self.request startAsynchronous];
}