It cloud be a JS/PNG/JPEG/HTML files as well as some custom fonts, css etc … I'm not controlling the content.
OK. Alas, there’s no way to make this work for WKWebView. The reason this works for UIWebView is that UIWebView runs entirely within your process and does its network requests with NSURLSession. NSURLSession consults NSURLProtocol subclasses, so you can insert yourself into the loading process.
In contrast, the bulk of WKWebView, and specifically the code making its network requests, runs outside of your process, and thus does not see your NSURLProtocol subclass.
As things currently stand you’ll have to stick with UIWebView. If you'd like to see WKWebView support this sort of thing in the future, I encourage you to file an enhancement request describing your requirements. Please post your bug number, just for the record.
Not sure, if NSURLCache can be used here.
NSURLCache will definitely not help here; like NSURLProtocol, it’s only consulted by network requests run in your process.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"