码迷,mamicode.com
首页 > 其他好文 > 详细

简单描述断点续传

时间:2015-11-05 14:52:31      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 1 // 下载结束之后,会调用
 2 // location 临时文件保存目录
 3 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
 4 didFinishDownloadingToURL:(NSURL *)location
 5 {
 6     NSString *path = @"/Users/apple/Desktop/QQQ.dmg";
 7     
 8     [[NSFileManager defaultManager] copyItemAtPath:location.path toPath:path error:NULL];
 9 }
10 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
11       didWriteData:(int64_t)bytesWritten
12  totalBytesWritten:(int64_t)totalBytesWritten
13 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
14 {
15     // 检测下载进度
16     
17     float progress = (float) totalBytesWritten/totalBytesExpectedToWrite;
18     
19     // 回到主线程 检测网络下载情况
20     dispatch_async(dispatch_get_main_queue(), ^{
21         //
22         self.progress.progress = progress;
23     });
24     
25 }
26        // 文件操作 不会造成内存飙升.文件剪切的操作
27         //[[NSFileManager defaultManager] moveItemAtPath:location.path toPath:path error:NULL];
28         
29         // 文件拷贝 如果涉及到 url的文件操作,都会导致内存飙升.
30         [[NSFileManager defaultManager] copyItemAtPath:location.path toPath:path error:NULL];
31         
32         // 下面这种文件操作方式.会造成内存飙升.
33         // [[NSFileManager defaultManager] moveItemAtURL:location toURL:url  error:NULL];
34     }];
35     

 

简单描述断点续传

标签:

原文地址:http://www.cnblogs.com/gp886/p/4939371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!