0

Can we use such a chain?

for example, I know urls like abc://wwww.example.com will be handled by a subclass of NSURLProtocol. But it is from a third party library and I do not have the source code to modify the response. So I provide another subclass of NSURLProtocol to handle urls like xyz://www.example.com. I am able to intercept and change urls from abc to xyz. In my own startLoading(), I changed the urls back from xyz to abc and use NSURLSession to send request to abc://www.example.com but got error and looks like the request did not go through the third party NSURPProtocol subclass.

any suggestion?

Rao
  • 51
  • 7

1 Answers1

0

NSURLProtocol subclasses are only registered globally for NSURLConnection. For NSURLSession, the registration is per-session.

If you want to register an NSURLProtocol in such a way that it would affect third-party libraries, the only way I'm aware of is by swizzling all of the session creation methods on NSURLSession and wrapping them with code that injects your custom protocol into the configuration on the way in.

dgatwood
  • 10,129
  • 1
  • 28
  • 49