Custom NSURLProtocol cannot handle requests from WKWebView

Originator:respectthecode
Number:rdar://18425900 Date Originated:9/23/14
Status:Duplicate of 17190141 (Open) Resolved:
Product:iOS Product Version:8.0
Classification: Reproducible:
 
Summary:
It was possible to install a custom NSURLProtocol to handle requests from UIWebView. This is no longer possible with WKWebView.

Steps to Reproduce:
1. Create and register a custom NSURLProtocol subclass that handles all requests.
2. Create a WKWebView and load a request.

Expected Results:
The custom NSURLProtocol subclass should receive a +canInitWithRequest: message, and then an instance should be created and initialized with -initWithRequest:cachedResponse:client:.

Actual Results:
The NSURLProtocol subclass *does* receive the +canInitWithRequest: message, but is never instantiated.

Version:
8.0

Notes:
The prevents us from using WKWebView

Configuration:
Any iOS device or Simulator

Comments

From the documentation: >The first NSURLProtocol subclass to return YES when sent a canInitWithRequest: message is used to perform the URL load. There is no guarantee that all registered protocol classes will be consulted. Classes are consulted in the reverse order of their registration. A similar design governs the process to create the canonical form of a request with canonicalRequestForRequest:.

When you register matters. It is entirely possible that another NSURLProtocol that can handle the request was registered after yours and is the one being used.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!