Search code examples
iosswiftfoundationurlsession

Example of URLProtocol usage?


I'm trying to figure out how URLProtocol works. Can you provide some cases of URLProtocol usage? What type of problems can it solve?


Solution

  • URLProtocol allows you to insert yourself into the URL loading system. I've used that for several things, from a simple offline caching system for UIWebView to intercepting Pandora traffic.

    I also sometimes implement my own schemes with an URLProtocol. For example, the server may send down a custom resource: link, and I'll use an URLProtocol to read that out of the bundle resources (basically the same as WKWebView's WKURLSchemeHandler for this).