Latest 0.1.0
Homepage https://github.com/WildDylan/WKWebViewWithURLProtocol
License MIT
Platforms ios 8.0
Frameworks Foundation, WebKit
Authors
introductions

MIT Licence

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 to fix this use runtime. Now-coming!

But Notice, WKWebView ignored HTTP Body in request, it’s a bug, resolve 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 known 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!

Notes: It’s only useful when systemVersion > iOS8.4

Some questions:

Q: Used private API when in review:

A: Watch this issue

Installation
pod "WKWebViewWithURLProtocol"
Author

Dylan, [email protected]

Thanks

@yeatse, Original repo without cocoapods

License

MIT License.

Latest podspec

{
    "name": "WKWebViewWithURLProtocol",
    "version": "0.1.0",
    "summary": "Make webView can hooked by URLProtocol.",
    "description": "Make webView can hooked by URLProtocol.",
    "homepage": "https://github.com/WildDylan/WKWebViewWithURLProtocol",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dylan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/WildDylan/WKWebViewWithURLProtocol.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "WKWebViewWithURLProtocol/**/*",
    "public_header_files": "WKWebViewWithURLProtocol/**/*.h",
    "frameworks": [
        "Foundation",
        "WebKit"
    ]
}

Pin It on Pinterest

Share This