iOS好使的各种文件文档、音乐、视频下载查看器有进度条
2017-12-20 14:29
1631 查看
一、使用说明
采用第三方下载插件MCDownloadManager,
csdn地址 http://download.csdn.net/download/wangxiaoertedaye/10166107
github地址 https://github.com/zxgiOS/MCDownloadManager
两种实现方式
1)分步式,点击下载然后点击打开,可以使用按钮点击下载、查看,
2)一体式,点击直接下载打开,点击之后将URL传入插件调用
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.url];
根据receipt.state判断是否下载或者直接打开,如果返回已下载就直接调用下述打开方法,未下载则调用下载方法下载完成后打开
二、效果图
三、使用方法
1.设置下载URL,设置进度条
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:url];
self.progressView.progress = receipt.progress.fractionCompleted;
2.点击开始下载,download中监听下载进度更新进度条
- (void)downloadBtnAction:(UIButton *)sender{
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.url];
if (receipt.state == MCDownloadStateDownloading) {//当前正在下载中
[sender setTitle:@"下载" forState:UIControlStateNormal];
[[MCDownloadManager defaultInstance] suspendWithDownloadReceipt:receipt];
}else if (receipt.state == MCDownloadStateCompleted) {//已下载
if ([self.delegate respondsToSelector:@selector(cell:didClickedBtn:)]) {
[self.delegate cell:self didClickedBtn:sender];
}
}else {//未下载
[sender setTitle:@"停止" forState:UIControlStateNormal];
[self download];
}
}
- (void)download {
[[MCDownloadManager defaultInstance] downloadFileWithURL:self.url
progress:^(NSProgress * _Nonnull downloadProgress, MCDownloadReceipt *receipt) {
NSLog(@"%@,%@",receipt.url,self.url);
if ([receipt.url isEqualToString:self.url]) {
self.progressView.progress = downloadProgress.fractionCompleted ;
self.sizeLabel.text = [NSString stringWithFormat:@"%0.2fm/%0.2fm", downloadProgress.completedUnitCount/1024.0/1024, downloadProgress.totalUnitCount/1024.0/1024];
}
}
destination:nil
success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSURL * _Nonnull filePath) {
[self.downloadBtn setTitle:@"查看" forState:UIControlStateNormal];
}
failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
[self.downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
}];
}
3.下载完成查看 传入需要查看文件的URL 插件自动关联已经下载好的(相当于缓存机制,避免重复下载)如果需要下载之后直接打开则在上述download方法下载完成中调用打开方法
- (void)openDocBycell:(DownLoadTableViewCell *)cell{
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:cell.url];
//UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
self.doc = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:receipt.filePath]];
self.doc.name = @"文档预览";
self.doc.accessibilityNavigationStyle = 2;
self.doc.delegate = self;
[self.doc presentPreviewAnimated:YES];
//[documentVC openFileWithURL:[NSURL fileURLWithPath:receipt.filePath]];
}
采用第三方下载插件MCDownloadManager,
csdn地址 http://download.csdn.net/download/wangxiaoertedaye/10166107
github地址 https://github.com/zxgiOS/MCDownloadManager
两种实现方式
1)分步式,点击下载然后点击打开,可以使用按钮点击下载、查看,
2)一体式,点击直接下载打开,点击之后将URL传入插件调用
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.url];
根据receipt.state判断是否下载或者直接打开,如果返回已下载就直接调用下述打开方法,未下载则调用下载方法下载完成后打开
二、效果图
三、使用方法
1.设置下载URL,设置进度条
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:url];
self.progressView.progress = receipt.progress.fractionCompleted;
2.点击开始下载,download中监听下载进度更新进度条
- (void)downloadBtnAction:(UIButton *)sender{
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.url];
if (receipt.state == MCDownloadStateDownloading) {//当前正在下载中
[sender setTitle:@"下载" forState:UIControlStateNormal];
[[MCDownloadManager defaultInstance] suspendWithDownloadReceipt:receipt];
}else if (receipt.state == MCDownloadStateCompleted) {//已下载
if ([self.delegate respondsToSelector:@selector(cell:didClickedBtn:)]) {
[self.delegate cell:self didClickedBtn:sender];
}
}else {//未下载
[sender setTitle:@"停止" forState:UIControlStateNormal];
[self download];
}
}
- (void)download {
[[MCDownloadManager defaultInstance] downloadFileWithURL:self.url
progress:^(NSProgress * _Nonnull downloadProgress, MCDownloadReceipt *receipt) {
NSLog(@"%@,%@",receipt.url,self.url);
if ([receipt.url isEqualToString:self.url]) {
self.progressView.progress = downloadProgress.fractionCompleted ;
self.sizeLabel.text = [NSString stringWithFormat:@"%0.2fm/%0.2fm", downloadProgress.completedUnitCount/1024.0/1024, downloadProgress.totalUnitCount/1024.0/1024];
}
}
destination:nil
success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSURL * _Nonnull filePath) {
[self.downloadBtn setTitle:@"查看" forState:UIControlStateNormal];
}
failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
[self.downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
}];
}
3.下载完成查看 传入需要查看文件的URL 插件自动关联已经下载好的(相当于缓存机制,避免重复下载)如果需要下载之后直接打开则在上述download方法下载完成中调用打开方法
- (void)openDocBycell:(DownLoadTableViewCell *)cell{
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:cell.url];
//UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
self.doc = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:receipt.filePath]];
self.doc.name = @"文档预览";
self.doc.accessibilityNavigationStyle = 2;
self.doc.delegate = self;
[self.doc presentPreviewAnimated:YES];
//[documentVC openFileWithURL:[NSURL fileURLWithPath:receipt.filePath]];
}
相关文章推荐
- ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)
- Android获取本机各种类型文件列表(音乐、视频、图片、文档等)
- 更改Windows的“视频”“图片”“”下载“文档”“音乐”“桌面”的默认路径
- android下载文件,文件包括视频以及各种文件
- iOS-网络-NSURLSessionDataTask实现大文件下载,进度提示
- ios使用AFN框架下载文件显示下载百分比带进度条
- iOS UI 15 网络编程下载 图片 音乐 大文件 视频 get/ post方法
- 如何为ios酷我音乐盒下载导出的音乐文件(使用Java程序设计)
- ios 使用NSURlSession 下载文件并且使用进度条进行文件下载进度读取以及打开附件(word,excel,ppt,pdf)显示
- iOS UI 15 网络编程下载 图片 音乐 大文件 视频 get/ post方法
- 【IOS学习】http异步文件上传和下载以及进度指示
- linux家目录下各默认目录的定义,如桌面,模板,音乐,公共,视频,文档,下载,图片等
- WIN10去除、恢复6个文件夹(视频、图片、文档、下载、音乐、桌面)的方法
- iOS开发之网络编程--4、NSURLSessionDataTask实现文件下载(离线断点续传下载) <进度值显示优化>
- 解决处女座看到win8这台电脑视频、图片、文档、下载、音乐、桌面等图标的显示
- 如何从ios酷我音乐盒中导出已下载的音乐文件(使用Java编程实现)
- html制作简单框架网页二 实现自己的影音驿站 操作步骤及源文件下载 (可播放mp4、avi、mpg、asx、swf各种文件的视频播放代码)
- iOS开发之网络编程--4、NSURLSessionDataTask实现文件下载(离线断点续传下载) <进度值显示优化>
- C# FileUpload上传视频、图片、文档,分别保存在不同的文件夹中以及下载文件的方法
- IOS下载查看PDF文件(有下载进度)