ios7新特性nsurlsession初探
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.
相關文章
- 開發者所需要知道的iOS7 SDK新特性iOS
- JDK 9新特性之Flow API 初探JDKAPI
- React 16.0+ 新特性初探(How to use)React
- 使用NSURLSessionSession
- 06-NSURLSessionSession
- ios7中引入的新類:nsprogress介紹iOS
- cocos2D-x初探學習筆記(31)2.1新特性CCPhysicsSprite筆記CSS
- NSURLSession 使用心得Session
- 深入瞭解 NSURLSessionSession
- NSURLSession和NSURLConnectionSession
- objc系列譯文(5.6):iOS7 的隱藏特性和解決之道OBJiOS
- 新特性
- Oracle11新特性——PLSQL新特性(七)OracleSQL
- Oracle11新特性——PLSQL新特性(六)OracleSQL
- Oracle11新特性——PLSQL新特性(五)OracleSQL
- Oracle11新特性——PLSQL新特性(四)OracleSQL
- Oracle11新特性——PLSQL新特性(三)OracleSQL
- Oracle11新特性——PLSQL新特性(二)OracleSQL
- Oracle11新特性——PLSQL新特性(一)OracleSQL
- NSURLSession的基礎用法Session
- 【ORACLE新特性】11G 分割槽新特性Oracle
- The Colors OF IOS7iOS
- React 新特性React
- 新特性介面
- 新特性方面
- 10G新特性筆記之安裝新特性筆記
- Servlet 3.0 新特性Servlet
- Go 1.13 新特性Go
- Java 11新特性Java
- PHP 7.4 新特性PHP
- Java 17新特性Java
- Prometheus 2.21.0 新特性Prometheus
- Java 8 新特性Java
- Hadoop新特性Hadoop
- MySQL 8.0 新特性MySql
- C++新特性C++
- PostgreSQL 13–新特性SQL
- Java 8 新特性Java