Class

NSURLSessionDownloadTask

A URL session task that stores downloaded data to a file. あるURLセッションタスク、それはダウンロードデータをあるファイルに格納します。

Declaration 宣言

@interface NSURLSessionDownloadTask : NSURLSessionTask

Overview 概要

An NSURLSessionDownloadTask is a concrete subclass of NSURLSessionTask, which provides most of the methods for this class. NSURLSessionDownloadTaskは、NSURLSessionTaskの具象サブクラスです、それはメソッドの大部分をこのクラスに対して提供します。

Download tasks directly write the server’s response data to a temporary file, providing your app with progress updates as data arrives from the server. When you use download tasks in background sessions, these downloads continue even when your app is in the suspended state or otherwise not running. ダウンロードタスクは、直接にサーバのもつ応答データを一時ファイルに書き出します、あなたのアプリに進捗最新情報をデータがサーバから到着するにつれて提供します。あなたがダウンロードタスクをバックグラウンドセッションにおいて使う場合、それらダウンロードは、あなたのアプリが一時停止状態であるまたはそれどころか動作していない時にさえ継続します。

You can pause (cancel) download tasks and resume them later (assuming the server supports doing so). You can also resume downloads that failed because of network connectivity problems. あなたは、ダウンロードタスクを一旦停止(取り消し)して、それらを後で再開できます(サーバがそうすることをサポートすると仮定して)。あなたはまた、ネットワーク接続性問題のために失敗したダウンロードを再開できます。

Download Delegate Behavior ダウンロード委任先挙動

When you use a download task, your delegate receives several callbacks unique to download scenarios. あなたがダウンロードタスクを使う場合、あなたの委任先はダウンロードセッションに対して特有である幾つかのコールバックを受け取ります。

  • During download, the session periodically calls the delegate’s URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite: method with status information. ダウンロードの間、セッションは周期的に委任先のもつURLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:メソッドを状態情報で呼び出します。

  • Upon successful completion, the session calls the delegate’s URLSession:downloadTask:didFinishDownloadingToURL: method or completion handler. In that method, you must either open the file for reading or move it to a permanent location in your app’s sandbox container directory. 成功裏の完了では、セッションは委任先のもつURLSession:downloadTask:didFinishDownloadingToURL:メソッドまたは完了ハンドラを呼び出します。そのメソッドにおいて、あなたは読み出すためにファイルを開くまたはそれをあなたのアプリのもつサンドボックスコンテナディレクトリの中のある永久的な場所に移動するかどちらかをしなければなりません。

  • Upon unsuccessful completion, the session calls the delegate’s URLSession:task:didCompleteWithError: method or completion handler. The only errors your delegate receives through the error parameter are client-side errors, such as being unable to resolve the hostname or connect to the host. To check for server-side errors, inspect the response property of the task parameter received by this callback. 不成功の完了では、セッションは委任先のもつURLSession:task:didCompleteWithError:メソッドまたは完了ハンドラを呼び出します。あなたの委任先がerrorパラメータを通して受け取るエラーだけが、クライアント側エラーです、たとえばホスト名が解決できないまたはホストに接続できないなど。サーバ側エラーを確認するには、このコールバックによって受け取られるtaskパラメータのresponseプロパティを調査してください。

Topics 話題

Canceling a Download ダウンロードを取り消す

Creating Download Tasks ダウンロードタスクを作成する

Relationships 関係

Inherits From 継承元

See Also 参照

Adding Download Tasks to a Session ダウンロードタスクをセッションに加える