Skip to content

davidkarn/WKWebViewWithURLProtocol

 
 

Repository files navigation

WKWebViewWithURLProtocol

introductions

After iOS8.0, WKWebView want to instead of UIWebView, but with some defects such as: URLProtocol can't process the request from WKWebView. WKWebViewWithURLProtocol want fix this use runtime. Now, coming!

But, Notice, WKWebView ignored the HTTP Body in reqiest, it'a bug. You can resolve it with Javascript bridge or NSURLSession.

[NSURLProtocol wk_registerScheme:@"http"];
[NSURLProtocol wk_registerScheme:@"https"];

[NSURLProtocol registerClass:[URLProtocol class]];

URLProtocol is the subclass of NSURLProtocol, before this, use wk_registerScheme to let URLProtocol know what scheme can be hooked from WKWebView. Now this demo want to hook http and https scheme.

[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.devdylan.cn"]]];

Now, open your custom URLProtocol, set some breakpoint or logs, oh my god! it's worked!

Some questions:

Q: Used private API when in review:

A: Watch this issue

Installation
pod "WKWebViewWithURLProtocol"
Author

Dylan, dylan@china.com

Thanks

@yeatse

License

MIT License.

About

WKWebView With URLProtocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 62.7%
  • Objective-C 33.8%
  • Ruby 3.5%