Mac Developer Library

Developer

Foundation Framework Reference NSURLProtocolClient Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSURLProtocolClient

Inheritance


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.2 with Safari 1.0 installed.
Available in OS X v10.2.7 and later.

The NSURLProtocolClient protocol provides the interface used by NSURLProtocol subclasses to communicate with the URL loading system. An application should never have the need to implement this protocol.

  • Sent to indicate to the URL loading system that a cached response is valid. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, cachedResponseIsValid cachedResponse: NSCachedURLResponse)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol cachedResponseIsValid:(NSCachedURLResponse *)cachedResponse

    Parameters

    protocol

    The URL protocol object sending the message.

    cachedResponse

    The cached response whose validity is being communicated.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent to indicate to the URL loading system that an authentication challenge has been canceled. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, didCancelAuthenticationChallenge challenge: NSURLAuthenticationChallenge)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

    Parameters

    protocol

    The URL protocol object sending the message.

    challenge

    The authentication challenge that was canceled.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent when the load request fails due to an error. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, didFailWithError error: NSError)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol didFailWithError:(NSError *)error

    Parameters

    protocol

    The URL protocol object sending the message.

    error

    The error that caused the failure of the load request.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • An NSURLProtocol subclass instance, protocol, sends this message to [protocol client] as it loads data. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, didLoadData data: NSData)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol didLoadData:(NSData *)data

    Discussion

    The data object must contain only new data loaded since the previous invocation of this method.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent to indicate to the URL loading system that an authentication challenge has been received. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

    Parameters

    protocol

    The URL protocol object sending the message.

    challenge

    The authentication challenge that has been received.

    Discussion

    The protocol client guarantees that it will answer the request on the same thread that called this method. The client may add a default credential to the challenge it issues to the connection delegate, if protocol did not provide one.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent to indicate to the URL loading system that the protocol implementation has created a response object for the request. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, didReceiveResponse response: NSURLResponse, cacheStoragePolicy policy: NSURLCacheStoragePolicy)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol didReceiveResponse:(NSURLResponse *)response cacheStoragePolicy:(NSURLCacheStoragePolicy)policy

    Parameters

    protocol

    The URL protocol object sending the message.

    response

    The newly available response object.

    policy

    The cache storage policy for the response.

    Discussion

    The implementation should use the provided cache storage policy to determine whether to store the response in a cache.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent to indicate to the URL loading system that the protocol implementation has been redirected. (required)

    Declaration

    Swift

    func URLProtocol(_ `protocol`: NSURLProtocol, wasRedirectedToRequest request: NSURLRequest, redirectResponse redirectResponse: NSURLResponse)

    Objective-C

    - (void)URLProtocol:(NSURLProtocol *)protocol wasRedirectedToRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse

    Parameters

    protocol

    The URL protocol object sending the message.

    request

    The new request that the original request was redirected to.

    redirectResponse

    The response from the original request that caused the redirect.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Sent to indicate to the URL loading system that the protocol implementation has finished loading. (required)

    Declaration

    Swift

    func URLProtocolDidFinishLoading(_ `protocol`: NSURLProtocol)

    Objective-C

    - (void)URLProtocolDidFinishLoading:(NSURLProtocol *)protocol

    Parameters

    protocol

    The URL protocol object sending the message.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.