ios7新特性nsurlsession初探
ios7引入了nsurlsession,通过它可以支持后台相关的网络操作的新特性。让我们看看它有哪些好处:
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.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。