URL Loading System URLローディングシステム

Interact with URLs and communicate with servers using standard Internet protocols. さまざまなURLと相互作用します、そしてさまざまなサービスと標準インターネットプロトコルを使って通信します。

Overview 概要

The URL Loading System provides access to resources identified by URLs, using standard protocols like https or custom protocols you create. Loading is performed asynchronously, so your app can remain responsive and handle incoming data or errors as they arrive. URLローディングシステムは、URLによって識別されるリソースへのアクセスを、httpsのような標準プロトコルまたはあなたが作成するあつらえのプロトコルを使って、提供します。ローディングは非同期に実行されます、なのであなたのアプリは依然として応答可能なままでそしてやってくるデータまたはエラーをそれらが到着すると同時に処理できます。

You use a NSURLSession instance to create one or more NSURLSessionTask instances, which can fetch and return data to your app, download files, or upload data and files to remote locations. To configure a session, you use a NSURLSessionConfiguration object, which controls behavior like how to use caches and cookies, or whether to allow connections on a cellular network. あなたは、ひとつのNSURLSessionインスタンスを使って1つ以上のNSURLSessionTaskインスタンスを作成します、それはデータをあなたのアプリから取ってくるそしてそれへと返す、ファイルをダウンロードする、またはデータとファイルを遠隔の場所にアップロードすることができます。セッションを構成設定するには、あなたはNSURLSessionConfigurationオブジェクトを使います、それはどのようにキャッシュおよびクッキーを使うか、またはセルラーネットワークでの接続を許可するかどうかといった挙動を制御します。

You can use one session repeatedly to create tasks. For example, a web browser might have separate sessions for regular and private browsing use, where the private session doesn’t cache its data. Figure 1 shows how two sessions with these configurations can then create multiple tasks. あなたは、1つのセッションを繰り返して使用してタスクそれらを作成できます。例えば、あるウェブブラウザは、通常のそしてプライベートのブラウジング用途に独立したセッションを持つかもしれません、そこにおいてプライベートセッションはそれのデータをキャッシュしません。図 1 は、どのように2つのセッションがそれらの構成設定をもち、それから複数のタスクを作成できるかを示します。

Figure 1 Creating tasks from URL sessions 図 1 URLセッションからタスクを作成する
Figure showing two scenarios, default browsing and private browsing, each with a URL Session creating multiple URL Session Tasks. In the default browsing case, the URL Session contains a default configuration. In the private browsing case, it contains an ephemeral configuration.

Each session is associated with a delegate to receive periodic updates (or errors). The default delegate calls a completion handler block that you provide; if you choose to provide your own custom delegate, this block is not called. それぞれのセッションは、ある委任先と結び付けられて、定期的な更新(またはエラー)を受け取ります。省略時の委任先は、あなたが提供する完了ハンドラブロックを呼び出します;あなたがあなた独自のあつらえの委任先を選ぶならば、このブロックは呼び出されません。

You can configure a session to run in the background, so that while the app is suspended, the system can download data on its behalf and wake up the app to deliver the results. あなたはあるセッションを構成設定してバックグラウンドで実行できます、それでアプリが一時停止されている間に、システムはデータをそれのためにダウンロードして、そしてアプリを起こしてその結果を届けられます。

Topics 話題

Essentials 要点

Configure and create sessions, then use them to create tasks that interact with URLs. セッションを構成設定して作成します、それからそれを使ってURLと相互作用するタスクを作成してください。

Requests and Responses 要請と応答

Uploading アップロード

Downloading ダウンロード

Cache Behavior キャッシュ挙動

Authentication and Credentials 認証と資格情報

Network Activity Attribution

Cookies さまざまなクッキー

Errors エラー

Legacy レガシー

See Also 参照

Networking ネットワーク関連