URLSessionDelegate

SDKs
iOS 7.0+
macOS 10.9+
tvOS 9.0+
watchOS 2.0+
Framework
Foundation

NSURLSessionDelegate协议描述URLSession对象在其delegates上调用以处理会话级别事件的方法。


概述

除了此协议中定义的方法之外,大多数delegates还应实现URLSessionTaskDelegateURLSessionDataDelegateURLSessionDownloadDelegate协议中的部分或全部方法来处理任务级别的事件。

注意

一个NSURLSession对象不需要delegate。如果未分配delegate,则使用系统提供的delegate,并且你必须提供完成回调以获取数据。


主题

一、代理方法

func urlSession(URLSession, didBecomeInvalidWithError: Error?)

通知URL会话该会话已失效。

func urlSession(URLSession, didReceive: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)

响应来自远程服务器的会话级别认证请求,从delegate请求证书。

func urlSessionDidFinishEvents(forBackgroundURLSession: URLSession)

告诉delegate,会话中所有的消息都已发送。

二、常量

enum URLSession.AuthChallengeDisposition

响应于认证质询,由会话或任务delegates传递的常量代表所提供的继续闭包。 Constants passed by session or task delegates to the provided continuation block in response to an authentication challenge.


关系

继承自

NSObjectProtocol

被继承


其他内容