1.设置请求头文件
// 取出文件操作对象
self.handle = [NSFileHandle fileHandleForWritingAtPath:_D_Path(self.tempPath)];
// 移动到文件结尾
unsigned long long length = [self.handle seekToEndOfFile];
NSString *urlStrEncoding = [self.URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStrEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:
1.0f];
// 设置请求头文件
NSString *rangeValue = [NSString stringWithFormat:@"bytes=%llu-", length];
[request addValue:rangeValue forHTTPHeaderField:@"Range"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
2.数据下载之后保存
// 保存数据
[self.handle writeData:self.data];
感觉比较简单,源代码就不贴完了