Instance Method インスタンスメソッド

urlSession(_:didReceive:completionHandler:)

Requests credentials from the delegate in response to a session-level authentication request from the remote server. リモートサーバからのセッション水準認証リクエストに応じて、委任先に資格情報を要請します。

Declaration 宣言

optional func urlSession(_ session: URLSession, 
              didReceive challenge: URLAuthenticationChallenge, 
       completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)

Parameters パラメータ

session

The session containing the task that requested authentication. 認証を要請したタスクを含んでいるセッション。

challenge

An object that contains the request for authentication. 認証に対する要請を含んでいるオブジェクト。

completionHandler

A handler that your delegate method must call. This completion handler takes the following parameters:: あなたの委任先メソッドが呼び出す必要があるハンドラ。この完了ハンドラは以下のパラメータを取ります:

  • disposition—One of several constants that describes how the challenge should be handled. disposition— いくつかの定数のうちの1つ、それはどのようにチャレンジが取り扱われるべきかを記述します。

  • credential—The credential that should be used for authentication if disposition is NSURLSessionAuthChallengeUseCredential, otherwise NULL. credential— もし意向がNSURLSessionAuthChallengeUseCredentialであるならば認証に使われるべき資格情報、そうでなければNULL

Discussion 議論

This method is called in two situations: このメソッドは、2つの状況で呼び出されます:

  • When a remote server asks for client certificates or Windows NT LAN Manager (NTLM) authentication, to allow your app to provide appropriate credentials リモートサーバがクライアント証明書またはWindows NT LAN Manager (NTLM) 認証について尋ねる時、あなたのアプリに適切な資格情報を提供できるようにするために

  • When a session first establishes a connection to a remote server that uses SSL or TLS, to allow your app to verify the server’s certificate chain セッションがSSLまたはTLSを使うリモートサーバに接続を最初に確立する時、あなたのアプリにサーバのもつ証明書チェーンを検証できるようにするために

If you do not implement this method, the session calls its delegate’s urlSession(_:task:didReceive:completionHandler:) method instead. あなたがこのメソッドを実装しないならば、セッションはそれの委任先のもつurlSession(_:task:didReceive:completionHandler:)メソッドを代わりに呼び出します。

See Also 参照

Handling Authentication Challenges 認証チャレンジを取り扱う