#import "ViewController.h"
#import <AFNetworking.h> @interface ViewController () - (IBAction)start:(UIButton *)sender; - (IBAction)pause:(UIButton *)sender; @property (weak, nonatomic) IBOutlet UIProgressView *pro; @property(nonatomic,strong) NSURLSessionDownloadTask *task; @end @implementation ViewController -(NSURLSessionDownloadTask *)task{ if (!_task) { AFHTTPSessionManager *session=[AFHTTPSessionManager manager]; NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"]]; _task=[session downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) { //下载进度
NSLog(@"%@",downloadProgress); [[NSOperationQueue mainQueue] addOperationWithBlock:^{ self.pro.progress=downloadProgress.fractionCompleted; }]; } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) { //下载到哪个文件夹
NSString *cachePath=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject; NSString *fileName=[cachePath stringByAppendingPathComponent:response.suggestedFilename]; return [NSURL fileURLWithPath:fileName]; } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) { //下载完成了
NSLog(@"下载完成了 %@",filePath);
}];
} return _task;
} - (void)viewDidLoad {
[super viewDidLoad];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; } - (IBAction)start:(UIButton *)sender { [self.task resume];
} - (IBAction)pause:(UIButton *)sender { [self.task suspend];
}
@end

AFNetworking 3.0 AFHTTPSessionManager文件下载的更多相关文章

  1. AFNetworking 3.0迁移指南

    AFNetworking是一款在OS X和iOS下都令人喜爱的网络库.为了迎合iOS新版本的升级, AFNetworking在3.0版本中删除了基于 NSURLConnection API的所有支持. ...

  2. [转]AFNetworking 3.0迁移指南

    http://www.jianshu.com/p/047463a7ce9b?utm_campaign=hugo&utm_medium=reader_share&utm_content= ...

  3. AFNetworking 3.0 源码解读(六)之 AFHTTPSessionManager

    AFHTTPSessionManager相对来说比较好理解,代码也比较短.但却是我们平时可能使用最多的类. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilit ...

  4. [置顶] AFNetworking 2.0 新特性讲解之AFHTTPSessionManager

    AFNetworking 2.0 相比1.0 API 接口改动还是很大的. 其中一个便是 AFURLSessionManager,当然如果你不太熟悉,或者为了兼容低版本,你依然可以选择AFHTTPRe ...

  5. AFNetworking 2.0 新特性讲解之AFHTTPSessionManager

    AFNetworking 2.0 新特性讲解之AFHTTPSessionManager (2014-02-17 11:56:24) 转载▼     AFNetworking 2.0 相比1.0 API ...

  6. AFNetworking 3.0 使用详解 和 源码解析实现原理

    AFN原理&& AFN如何使用RunLoop来实现的: 让你介绍一下AFN源码的理解,首先要说说封装里面主要做了那些重要的事情,有那些重要的类(XY题) 一.AFN的实现步骤: NSS ...

  7. AFNetworking 3.0 源码解读(十一)之 UIButton/UIProgressView/UIWebView + AFNetworking

    AFNetworking的源码解读马上就结束了,这一篇应该算是倒数第二篇,下一篇会是对AFNetworking中的技术点进行总结. 前言 上一篇我们总结了 UIActivityIndicatorVie ...

  8. AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking

    我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...

  9. AFNetworking 3.0 源码解读(九)之 AFNetworkActivityIndicatorManager

    让我们的APP像艺术品一样优雅,开发工程师更像是一名匠人,不仅需要精湛的技艺,而且要有一颗匠心. 前言 AFNetworkActivityIndicatorManager 是对状态栏中网络激活那个小控 ...

随机推荐

  1. $(QTDIR);$(QTDIR)\include\QtCore;$(QTDIR)\include;

    $(QTDIR); 在系统环境变量中定义即可  vs属性中设置头文件路径

  2. JSTL(JSP标准标签库)

    JSP标准标签库(JavaServer Pages Tag Library, JSTL)是一个定制JSP标签库的集合,封装了JSP应用的通用核心功能.用来解决像遍历Map或集合.条件测试.XML处理, ...

  3. SCM_SVN_CVS

    SCM_SVN_CVS SCM:一种用于记录并控制软件数据的工具.比如有:CVS(有过时趋势)和SVN(更加常用). 版本控制的概念: Respository:仓库 Workspace:工作台 Del ...

  4. 【UI测试】--菜单位置

  5. 459. Repeated Substring Pattern

    https://leetcode.com/problems/repeated-substring-pattern/#/description Given a non-empty string chec ...

  6. 2018.10.26 NOIP模拟 性感手枪(搜索)

    传送门 vis[x][y]vis[x][y]vis[x][y]记录这个点是否在之前被搜过,且被搜过的坐标是什么. 然后搜索的时候记录一个循环的下标和不循环的下标就行了. 代码

  7. PHP获取手机号

    /** * 类名: mobile * 描述: 手机信息类 * 其他: 偶然 编写 */ class mobile{ /** * 函数名称: getPhoneNumber * 函数功能: 取手机号 * ...

  8. Bootstrap Table 超多列 使用滚动条

    overflow-x: scroll;横向滑动详细讲解 able显示滚动条,要先把table放到一个div中,控制div 属性overflow值为scroll <div style=" ...

  9. git只合并某一个分支的某个commit

    第一种情况:只合并一个commit git checkout develop-hbb git cherry-pick 7c32be61 以上,7c32be61是develop上的一个fix bug的c ...

  10. mybatis xml中的大于、小于等符号写法

    xml特殊符号转义写法 <          < >          > <>   <> &      & &apos;   ...