There isn’t a good way to do this. For UIWebView you can use an NSURLProtocol (as illustrated by the CustomHTTPProtocol sample code) but it’s a bunch of work and has a lot of sharp edge cases.
For WKWebView, which is what we recommend that folks use, the networking is done out of process and thus the NSURLProtocol technique does not work.
Regardless of what else you do here, you should file an enhancement request for direct support for this in WKWebView. Please post your bug number, just for the record.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"