Class

NSURLProtocol

An NSURLProtocol object handles the loading of protocol-specific URL data. The NSURLProtocol class itself is an abstract class that provides the infrastructure for processing URLs with a specific URL scheme. You create subclasses for any custom protocols or URL schemes that your app supports.

Overview

Apps never need to instantiate an NSURLProtocol subclass directly. When a download starts, the system creates the appropriate protocol object to handle the corresponding URL request. All you have to do is define your protocol class and call the registerClass: class method during your app’s launch time so that the system is aware of your protocol.

To support the customization of protocol-specific requests, you are encouraged to define categories on NSURLRequest and NSMutableURLRequest with any custom API that you need. Protocol implementors who need to extend the capabilities of NSURLRequest and NSMutableURLRequest in this way can store and retrieve protocol-specific request data by using NSURLProtocol’s class methods propertyForKey:inRequest: and setProperty:forKey:inRequest:.

An essential responsibility for a protocol implementor is creating a NSURLResponse for each request it processes successfully. A protocol implementor may wish to create a custom, mutable NSURLResponse class to provide protocol specific information.

Symbols

Creating Protocol Objects

- initWithRequest:cachedResponse:client:

Initializes and returns the protocol object.

Registering and Unregistering Protocol Classes

+ registerClass:

Attempts to register a subclass of NSURLProtocol, making it visible to the URL loading system.

+ unregisterClass:

Unregisters the specified subclass of NSURLProtocol.

Determining If a Subclass Can Handle a Request

+ canInitWithRequest:

Returns whether the protocol subclass can handle the specified request.

Getting and Setting Request Properties

+ propertyForKey:inRequest:

Returns the property associated with the specified key in the specified request.

+ setProperty:forKey:inRequest:

Sets the property associated with the specified key in the specified request.

+ removePropertyForKey:inRequest:

Removes the property associated with the specified key in the specified request.

Providing a Canonical Version of a Request

+ canonicalRequestForRequest:

Returns a canonical version of the specified request.

Determining If Requests Are Cache Equivalent

+ requestIsCacheEquivalent:toRequest:

Returns whether two requests are equivalent for cache purposes.

Starting and Stopping Downloads

- startLoading

Starts protocol-specific loading of the request.

- stopLoading

Stops protocol-specific loading of the request.

Getting Protocol Attributes

cachedResponse

The receiver’s cached response.

client

The object the receiver uses to communicate with the URL loading system.

request

The receiver’s request.

Instance Properties

Type Methods

Relationships

Inherits From