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

cancel(byProducingResumeData:)

Cancels a download and calls a callback with resume data for later use. ダウンロードを取り消して、あるコールバックを後で使うための再開データで呼び出します。

Declaration 宣言

func cancel(byProducingResumeData completionHandler: @escaping (Data?) -> Void)

Parameters パラメータ

completionHandler

A completion handler that is called when the download has been successfully canceled. ある完了ハンドラ、それはダウンロードが成功裏に取り消された場合に呼び出されます。

If the download is resumable, the completion handler is provided with a resumeData object. Your app can later pass this object to a session’s downloadTask(withResumeData:) or downloadTask(withResumeData:completionHandler:) method to create a new task that resumes the download where it left off. ダウンロードが再開可能であるならば、完了ハンドラはresumeDataを提供されます。あなたのアプリは、後でこのオブジェクトをセッションのもつdownloadTask(withResumeData:)またはdownloadTask(withResumeData:completionHandler:)メソッドに渡して、ダウンロードをそれが中断したところで再開するある新しいタスクを作成できます。

This block is not guaranteed to execute in a particular thread context. As such, you may want specify an appropriate dispatch queue in which to perform any work. このブロックは、ある特定のスレッド文脈で遂行することを保証されません。そういうことで、あなたは適切なディスパッチキューを指定してそれにおいて何らかの仕事を実行するようにしたいかもしれません。

Discussion 議論

A download can be resumed only if the following conditions are met: ダウンロードが、以下の条件が合う場合にのみ再開されることができます:

  • The resource has not changed since you first requested it リソースが、あなたが最初にそれを要請したときから変化していない

  • The task is an HTTP or HTTPS GET request タスクが、HTTPまたはHTTPS GETリクエストである

  • The server provides either the ETag or Last-Modified header (or both) in its response サーバが、ETagまたはLast-Modifiedヘッダのどちらか(または両方)をそれの応答において提供する

  • The server supports byte-range requests サーバが、「バイト範囲」リクエストをサポートする

  • The temporary file hasn’t been deleted by the system in response to disk space pressure 一時ファイルが、システムによってディスクの空きの窮迫に応じて削除されていない