Both nsurlsession and nsurlconnection work similarly at high level for most of the part.
大部分相似
nsurlsesion provides support for download task which behave same like nsurldownload class.
when we create a nsurlsession object it provides reusable(可复用的) configuration object that encapsulates(封装) many common configurations options. but for nsurlconnection object we must set those each options independently.
nsurlconnections object handles single request and any follow on request.nsurlsession handles multiple tasks each of which single url request and any follow on request.
in nsurlconnection , each connection object has separate delegate.
in nsurlsession , delegate is shared across all tasks within a session.if we need new delegate , we must create new session.
nsurlconnection is older api introduced in os x 10.2
nsurlconnection is introduced in os x 10.9 which is modern having task and block based API.
Big difference is nsurlsession provides ability to perform background downloads when app is not running.
- encapsulates 压缩、将…装入胶囊;将…封进内部;概述 。
总结
- 大部分相似
- session,意思是会话,顾名思义,nsurlsession功能要多,包含上传、下载等功能
- 每个nsurlconnection都有一个单独的代理,一个session能包含很多任务
- 最大的不同是后台下载