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.
- iOS 2.0+
- macOS 10.2+
- tvOS 9.0+
- watchOS 2.0+
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
register 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
NSMutable with any custom API that you need. Protocol implementors who need to extend the capabilities of
NSMutable in this way can store and retrieve protocol-specific request data by using
NSURLProtocol’s class methods
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.