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

URLSession:dataTask:didReceiveResponse:completionHandler:

Tells the delegate that the data task received the initial reply (headers) from the server. データタスクが最初の応答(ヘッダ)をサーバから受け取ったことを委任先に伝えます。

Declaration 宣言

- (void)URLSession:(NSURLSession *)session 
          dataTask:(NSURLSessionDataTask *)dataTask 
didReceiveResponse:(NSURLResponse *)response 
 completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler;

Parameters パラメータ

session

The session containing the data task that received an initial reply. 最初の返答を受け取ったデータタスクを含んでいるセッション。

dataTask

The data task that received an initial reply. 最初の返答を受け取ったデータタスク。

response

A URL response object populated with headers. ヘッダそれらで満たされたURL応答オブジェクト。

completionHandler

A completion handler that your code calls to continue a transfer, passing a NSURLSessionResponseDisposition constant to indicate whether the transfer should continue as a data task or should become a download task. あなたのコードがある転送を継続するために呼び出すある完了ハンドラ、NSURLSessionResponseDisposition定数を渡すことで転送がデータタスクとして継続すべきかまたはダウンロードタスクになるべきかどうかを指し示します。

Discussion 議論

Implementing this method is optional unless you need to cancel the transfer or convert it to a download task when the response headers are first received. If you don’t provide this delegate method, the session always allows the task to continue. このメソッドを実装することは随意です、応答ヘッダが最初に受け取られる場合にあなたがその転送を取り消すまたはそれをダウンロードタスクに変換する必要がある場合を除いて。あなたがこの委任先メソッドを提供しないならば、セッションは常にタスクの継続を許可します。

You also implement this method if you need to support the fairly obscure multipart/x-mixed-replace content type. With that content type, the server sends a series of parts, each of which is intended to replace the previous part. The session calls this method at the beginning of each part, followed by one or more calls to URLSession:dataTask:didReceiveData: with the contents of that part. あなたはまたこのメソッドを、もしあなたが相当に曖昧なmultipart/x-mixed-replaceコンテンツタイプをサポートする必要があるならば実装します。そのコンテンツタイプでは、サーバは一連の部分を送信します、そのそれぞれが前の部分を置き換えることを意図されます。セッションは、このメソッドを各部の始まりで呼び出します、その後に1つ以上のURLSession:dataTask:didReceiveData:への呼び出しをその部分の内容をつかって続けます。

Each time the URLSession:dataTask:didReceiveResponse:completionHandler: method is called for a part, collect the data received for the previous part (if any) and process the data as needed for your application. This processing can include storing the data to the filesystem, parsing it into custom types, or displaying it to the user. Next, begin receiving the next part by calling the completion handler with the NSURLSessionResponseAllow constant. Finally, if you have also implemented URLSession:task:didCompleteWithError:, the session will call it after sending all the data for the last part. URLSession:dataTask:didReceiveResponse:completionHandler:メソッドがある部分に対して呼び出されるたびに、前の部分に対して受け取られたデータを集めて(もしあれば)そしてそのデータをあなたのアプリケーションの必要に応じて処理します。この処理は、データをファイルシステムに格納する、それをあつらえの型へと構文解析する、またはそれをユーザに表示することを含むことができます。その次に、次の部分を受け取ることを、完了ハンドラをNSURLSessionResponseAllow定数で呼び出すことで始めます。最後に、あなたがまたURLSession:task:didCompleteWithError:も実装したならば、セッションはそれを最後の部分に対する全てのデータを送る後に呼び出すでしょう。

See Also 参照

Handling Task Life Cycle Changes タスクライフサイクル変化を取り扱う