-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deal With WKWebView DNS pollution problem in iOS11 #16
Comments
unable to handle http and https[_webView.configuration setURLSchemeHandler:self forURLScheme:@"http"];
[_webView.configuration setURLSchemeHandler:self forURLScheme:@"https"]; *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ''http' is a URL scheme that WKWebView handles natively'
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ''https' is a URL scheme that WKWebView handles natively'
same with reasonReference: Source Code - (void)setURLSchemeHandler:(id <WKURLSchemeHandler>)urlSchemeHandler forURLScheme:(NSString *)urlScheme
{
auto *urlSchemeHandlers = _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
if ([WKWebView handlesURLScheme:urlScheme])
[NSException raise:NSInvalidArgumentException format:@"'%@' is a URL scheme that WKWebView handles natively", urlScheme];
auto canonicalScheme = WebCore::URLParser::maybeCanonicalizeScheme(urlScheme);
if (!canonicalScheme)
[NSException raise:NSInvalidArgumentException format:@"'%@' is not a valid URL scheme", urlScheme];
if ([urlSchemeHandlers objectForKey:(NSString *)canonicalScheme.value()])
[NSException raise:NSInvalidArgumentException format:@"URL scheme '%@' already has a registered URL scheme handler", urlScheme];
[urlSchemeHandlers setObject:urlSchemeHandler forKey:(NSString *)canonicalScheme.value()];
} why?the new API function is not for request handling, the function looks like this: //OC register scheme for JS to invoke
[[_webView configuration].userContentController addScriptMessageHandler:self name:@"closeMe"];
//OC operation after JS method invoked
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
NSLog(@"JS invoke %@ method,paramers is %@",message.name,message.body);
}
//JS invoke:
window.webkit.messageHandlers.closeMe.postMessage(null); the feature is more like WebViewJavascriptBridge , rather than NSURLProtocol. |
So can the new API The answer is CANNOT. |
iOS11 new API
|
阿西吧 那不是僵硬了 不能处理http和https请求,WKWebView在NSURLProtocol下问题多啊 |
@lucifer717 参考这里:ChenYilong/iOSBlog#11 |
@ChenYilong OK thx |
iOS 11 WKWebView provides APIs which work like NSURLProtocol in UIWebView, it's useful to WKWebView DNS pollution problem.
New API
-[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:]
,provideWKURLSchemeHandler
to handle the request with your network tool.Reference: Apple API Doc
The text was updated successfully, but these errors were encountered: