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

connection(_:willSend:redirectResponse:)

Sent when the connection determines that it must change URLs in order to continue loading a request. それがリクエストのロードを継続するためにURLを変更しなければならないことを接続が決定する場合に送られます。

Declaration 宣言

optional func connection(_ connection: NSURLConnection, 
                willSend request: URLRequest, 
        redirectResponse response: URLResponse?) -> URLRequest?

Parameters パラメータ

connection

The connection sending the message. メッセージを送っている接続。

request

The proposed redirected request. The delegate should inspect the redirected request to verify that it meets its needs, and create a copy with new attributes to return to the connection if necessary. 提案されたリダイレクト用リクエスト。委任先は、リダイレクト用リクエストを検査することで、それがそれの要求を満たすことを検証するべきです、そしてコピーを新しい属性で作成して接続へと返すべきです、もし必要ならば。

redirectResponse

The URL response that caused the redirect. May be nil in cases where this method is called because of URL canonicalization. リダイレクトを引き起こしたURL応答。nilであるかもしれません、URL正規化のためにこのメソッドが呼び出される場合には。

Return Value 戻り値

The actual URL request to use in light of the redirection response. The delegate may return request unmodified to allow the redirect, return a new request, or return nil to reject the redirect and continue processing the connection. リダイレクト応答に照らして使われることになる実際のURLリクエスト。委任先は、リダイレクトを可能にするために未変更requestを返す、新しいリクエストを返す、またはリダイレクトを拒否して接続の処理を継続するためにnilを返すかもしれません。

Discussion 議論

If redirectResponse is nil, the URL was canonicalized (rewritten into its standard form) by the URLProtocol object handling the request. Update your user interface to show the standardized form of the URL, then return the original request unmodified. redirectResponsenilならば、URLは正規化されました(それの標準形式へと書き直された)、URLProtocolオブジェクトがリクエストを取り扱うことによって。あなたのユーザインターフェイスを更新することで標準化形式のURLを表示してください、それから未修正の元のリクエストを返してください。

Otherwise, to cancel the redirect, call the connection object’s cancel method, then return the provided request object. そうでなければ、リダイレクトをキャンセルするために、connectionオブジェクトのもつcancelメソッドを呼び出してください、それから提供されたリクエストオブジェクトを返してください。

To receive the body of the redirect response itself, return nil to cancel the redirect. The connection continues to process, eventually sending your delegate a connectionDidFinishLoading or connection:didFailLoadingWithError: message, as appropriate. リダイレクト応答それ自体のボディを受け取るには、nilを返してリダイレクトをキャンセルしてください。接続は処理を継続します、結局はあなたの委任先にconnectionDidFinishLoadingまたはconnection:didFailLoadingWithError:メッセージを送ります、適切に。

To redirect the request to a different URL, create a new request object and return it. リクエストを異なるURLにリダイレクトするには、新しいリクエストオブジェクトを作成して、それを返してください。

The delegate should be prepared to receive this message multiple times. 委任先は、このメッセージを複数回受け取る用意があるべきです。

See Also 参照

Handling Redirects リダイレクトを取り扱う