首页 > 其他 > 详细

简单描述断点续传

时间:2015-11-05 14:51:46      阅读:178      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!