2019独角兽企业重金招聘Python工程师标准>>>

//
//  ViewController.m
//  AFN下载
//
//  Created by chen on 15/2/22.
//  Copyright (c) 2015年 lanrw. All rights reserved.
//#import "ViewController.h"
#import "AFNetworking.h"@interface ViewController () <NSURLSessionDownloadDelegate>
@property (nonatomic,strong) NSURLSession *session;
@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];
}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{/***  简单的下载*/
//    [self downloadFile];/***  有进度的下载*/[self downloadFile2];
}/***  简单的下载*/
- (void)downloadFile
{AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/post/abc/07.mp4"] cachePolicy:1 timeoutInterval:6];[[manger downloadTaskWithRequest:request progress:NULL destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:response.suggestedFilename];NSURL *url = [NSURL fileURLWithPath:filePath];return url;} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {NSLog(@"%@",error.localizedDescription);}] resume];
}
/***  使用代理监控下载进度*/
- (void)downloadFile2
{NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/post/abc/07.mp4"] cachePolicy:1 timeoutInterval:15];[[self.session downloadTaskWithRequest:request]resume];
}#pragma mark - 代理方法
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{NSString *pathFile = [NSTemporaryDirectory() stringByAppendingPathComponent:downloadTask.response.suggestedFilename];NSFileManager *manger = [NSFileManager defaultManager];[manger copyItemAtPath:location.path toPath:pathFile error:NULL];
}
// 进度数据
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{float progress = (float)totalBytesWritten / totalBytesExpectedToWrite;NSLog(@"%f",progress);
}// 懒加载
- (NSURLSession *)session
{if(_session == nil){NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];}return _session;
}@end

http://pan.baidu.com/s/1eQiZSzg

转载于:https://my.oschina.net/lanrenbar/blog/379513

iOS网络 AFN简单的下载 与 session下载带进度数据相关推荐

  1. iOS网络——身份认证

    iOS网络身份认证 文档 URL Session Programming Guide中重要的类如下: 在Networking Overview--Making HTTP and HTTPS Reque ...

  2. java版欧朋浏览器_Opera欧朋浏览器_Opera欧朋浏览器下载[2020官方最新版]Opera欧朋浏览器安全下载_ 极速下载...

    Opera(64位)为来自挪威的一个极为出色的浏览器,具有速度快.节省系统资源.订制能力强.安全性高以及体积小等特点,目前已经是最受欢迎的浏览器之一.多文件接口(MDI).方便的缩放功能.整合搜索引擎 ...

  3. C#winform 从ftp下载文件(带进度条)、获取文件(夹)的名字

    直接用地址下载,引用进度条: ​/// <summary>/// 从ftp服务器下载文件的功能----带进度条/// </summary>/// <param name= ...

  4. Android FTP 客户端 上传/下载 带进度条实战源码

    Android FTP 开发,我个人是使用commons-net-3.1.jar,别问我为什么是度娘教我的,附上commons-net-3.1.jar的开源下载地址http://grepcode.co ...

  5. iOS网络-NSURLSessionDataTask大文件离线断点下载

    什么叫离线断点下载,就是用户下载中关闭程序重新打开可以继续下载 代码实现如下: #import "ViewController.h" @interface ViewControll ...

  6. iOS网络NSURLSession使用详解

    一.整体介绍 NSURLSession在2013年随着iOS7的发布一起面世,苹果对它的定位是作为NSURLConnection的替代者,然后逐步将NSURLConnection退出历史舞台.现在使用 ...

  7. iOS网络2——NSURLSession使用详解

    原文在此 一.整体介绍 NSURLSession在2013年随着iOS7的发布一起面世,苹果对它的定位是作为NSURLConnection的替代者,然后逐步将NSURLConnection退出历史舞台 ...

  8. iOS网络缓存扫盲篇--使用两行代码就能完成80%的缓存需求

    原文地址:https://github.com/ChenYilong/ParseSourceCodeStudy/blob/master/02_Parse的网络缓存与离线存储/iOS网络缓存扫盲篇.md ...

  9. iOS网络编程开发—HTTP协议

    iOS网络编程开发-HTTP协议 说明:apache tomcat服务器必须占用8080端口 一.URL 1.基本介绍 URL的全称是Uniform Resource Locator(统一资源定位符) ...

  10. iOS 如何实现 AppStore 中App 的自动下载

    这次的分享是关于如何在 AppStore 实现 App 的自动下载,理想中的目标是只需要一部手机,不需要人来干预,就可以模拟用户的真实下载,并在下载完成以后,可以自动更改手机参数,使之变为另外一部苹果 ...

最新文章

  1. 入职大厂,我容易吗?
  2. Linux中安装配置hadoop集群
  3. myeclipse 2019中文版
  4. hdu1978(递推dp)
  5. liferay 导入源码问题
  6. 20170626_oracle_数据库设计
  7. 开工啦~Spring 完美导入 IDEA
  8. Redlock 算法:Redis 实现分布式锁(译)
  9. 面向对象的三个特点:封装、继承、多态
  10. cas与java锁_JAVA之锁-cas
  11. 【算法】—— str2int(正序和逆序)
  12. Looper对文件描述符的监控与处理
  13. lightbox使用
  14. 禅定是否一定要打坐,为什么?
  15. 阿帕网几台大型计算机网络,阿帕网-互联网的鼻祖(中) | 午夜猫
  16. Docker基础认识与docker安装以及环境配置
  17. 人脸识别、深度学习优秀设计(毕业专业指导)
  18. 大明最不该被遗忘的英烈——李定国
  19. wkhtmltopdf使用指南,html转图片,转pdf
  20. java的像素与dpi_对屏幕的理解---分辨率,dpi,ppi,屏幕尺寸,像素 等

热门文章

  1. git 拉新项目_Git学习系列之Git基本操作拉取项目(图文详解)
  2. mybatis update 不为空的_详解MyBatis-Plus updateById方法更新不了空字符串/null解决方法...
  3. hadoop 2.6.4 java_Windows下使用Hadoop2.6.0
  4. 【安装包】WinSCP
  5. L1-030 一帮一 (15 分)—团体程序设计天梯赛
  6. centos赋予访问权限
  7. 微云笔记控制脚本实例:远程控制脚本开关
  8. 关于动态规格的新理解
  9. 走进AngularJs(一)angular基本概念的认识与实战
  10. jxl freemark