ios7新特性nsurlsession初探

iOS7引入NSURLSession:网络操作新特性
iOS7引入了NSURLSession,它为后台上传下载提供了便利,并允许网络操作的暂停和恢复,无需使用NSOperation。此外,它可以作为可配置容器,设置HTTP头属性,每个请求在指定代理方法中进行处理,支持私有存储,并改进了鉴权处理。

ios7引入了nsurlsession,通过它可以支持后台相关的网络操作的新特性。让我们看看它有哪些好处:

1.后台上传下载;
2.不需要通过nsoperation,我们用nsurlsession的api就可以做到网络操作的暂停和恢复。
3.作为可配置的容器:例如你可以设置http头的一些属性并且保存在session里,你就不用重复去做配置了;don't repeat yourself~
4.可以子类化并支持私有的存储;
5.对鉴权的回调做了改进,此前nsurlconnection的鉴权回调无法和请求进行匹配,该回调可能来自任意的请求;而现在每个请求都可以在指定的代理方法中对其进行处理.


翻译材料如下:(来自链接:http://www.raywenderlich.com/51127/nsurlsession-tutorial)

Why Use NSURLSession?

Why should you use NSURLSession? Well, it brings you a number of new advantages and benefits:

  • Background uploads and downloads: With just a configuration option when the NSURLSession is created, you get all the benefits of background networking. This helps with battery life, supports UIKit multitasking and uses the same delegate model as in-process transfers.
  • Ability to pause and resume networking operations: As you will see later, with the NSURLSession API any networking task can be paused, stopped, and restarted. No NSOperation sub-classing necessary.
  • Configurable container: Each NSURLSession is the configurable container for putting requests into. For example, if you need to set an HTTP header option you will only need to do this once and each request in the session will have the same configuration.
  • Subclassable and private storage: NSURLSession is subclassable and you can configure a session to use private storage on a per session basis. This allows you to have private storage objects outside of the global state.
  • Improved authentication handling: Authentication is done on a specific connection basis. When using NSURLConnection if an authentication challenge was issued, the challenge would come back for an arbitrary request, you wouldn’t know exactly what request was getting the challenge. WithNSURLSession, the delegate handles authentication.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值