• <i id='cdgLs'><tr id='cdgLs'><dt id='cdgLs'><q id='cdgLs'><span id='cdgLs'><b id='cdgLs'><form id='cdgLs'><ins id='cdgLs'></ins><ul id='cdgLs'></ul><sub id='cdgLs'></sub></form><legend id='cdgLs'></legend><bdo id='cdgLs'><pre id='cdgLs'><center id='cdgLs'></center></pre></bdo></b><th id='cdgLs'></th></span></q></dt></tr></i><div id='cdgLs'><tfoot id='cdgLs'></tfoot><dl id='cdgLs'><fieldset id='cdgLs'></fieldset></dl></div>

      <bdo id='cdgLs'></bdo><ul id='cdgLs'></ul>
    <legend id='cdgLs'><style id='cdgLs'><dir id='cdgLs'><q id='cdgLs'></q></dir></style></legend>

    <small id='cdgLs'></small><noframes id='cdgLs'>

    1. <tfoot id='cdgLs'></tfoot>

        WKWebView 和 NSURLProtocol 不起作用

        时间:2023-10-23
        <legend id='flB4Y'><style id='flB4Y'><dir id='flB4Y'><q id='flB4Y'></q></dir></style></legend>

                <bdo id='flB4Y'></bdo><ul id='flB4Y'></ul>
                <tfoot id='flB4Y'></tfoot>
                <i id='flB4Y'><tr id='flB4Y'><dt id='flB4Y'><q id='flB4Y'><span id='flB4Y'><b id='flB4Y'><form id='flB4Y'><ins id='flB4Y'></ins><ul id='flB4Y'></ul><sub id='flB4Y'></sub></form><legend id='flB4Y'></legend><bdo id='flB4Y'><pre id='flB4Y'><center id='flB4Y'></center></pre></bdo></b><th id='flB4Y'></th></span></q></dt></tr></i><div id='flB4Y'><tfoot id='flB4Y'></tfoot><dl id='flB4Y'><fieldset id='flB4Y'></fieldset></dl></div>
                  <tbody id='flB4Y'></tbody>

                  <small id='flB4Y'></small><noframes id='flB4Y'>

                  本文介绍了WKWebView 和 NSURLProtocol 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用旧的 UIWebView 时,您可以通过实现自定义 NSURLProtocol 来捕获请求.我用它来处理需要身份验证的请求.

                  When using the old UIWebView you could catch the requests by implementing a custom NSURLProtocol. I us this to handle requests that requires authentication.

                  我尝试了相同的代码,但它不适用于新的 WKWebView,但我的协议类根本没有被调用.有人遇到同样的问题还是有更好的方法来使用 WKWebView 进行身份验证?

                  I tried the same code and it doesn't work with the new WKWebView but my protocol class isn't called at all. Is someone experiencing the same problem or is there a better way of doing authentication with the WKWebView?

                  在没有任何修改的情况下,我在 decisionPolicyForNavigationResponse 委托函数中得到了 401 响应.我还尝试使用 NSURLConnection 连接到服务器并使用 NSURLConnectionDataDelegate 处理身份验证.这可行,但 WKWebView 不会获取存储的凭据.

                  Without any modifications I get a 401 response in the decidePolicyForNavigationResponse delegate function. I've also tried connection to the server with a NSURLConnection and handling the authentication with a NSURLConnectionDataDelegate. That works but the stored credentials isn't picked up by the WKWebView.

                  推荐答案

                  iOS 11 和 macOS 10.13 的更新答案

                  从iOS 11开始可以声明一个符合WKURLSchemeHandler协议的对象,并在WKWebView配置中注册:-[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:].

                  Updated answer for iOS 11 and macOS 10.13

                  Since iOS 11 it is possible to declare an object that conforms to the WKURLSchemeHandler protocol and register it in the WKWebView configuration: -[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:].

                  WKWebView 发出请求并在进程外呈现内容,这意味着您的应用不会听到它们发出的请求.如果您缺少某个功能,现在是时候向 Apple 提交错误报告和/或改进请求了.

                  WKWebView makes requests and renders content out-of-process, meaning your app does not hear the requests they make. If you are missing a functionality, now is the time to open a bug report and/or an enhancement request with Apple.

                  从 iOS 10.3 SDK 开始,WKWebView 仍然无法通过公共 API 使用自定义 NSURLProtocol.

                  As of iOS 10.3 SDK, WKWebView is still unable to make use of custom NSURLProtocols using public APIs.

                  有进取心的开发者发现了一个有趣的方法:+[WKBrowsingContextController registerSchemeForCustomProtocol:]它应该将提供的方案添加到自定义协议处理方案列表中,然后应该与 NSURLProtocol 一起使用.

                  Enterprising developers have found an interesting method: +[WKBrowsingContextController registerSchemeForCustomProtocol:] It supposedly adds the provided scheme to a list of custom protocol handled schemes and should then work with NSURLProtocol.

                  这篇关于WKWebView 和 NSURLProtocol 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIWebView 支持的文件格式 下一篇:使用 POST 参数通过 UIWebView 加载网页

                  相关文章

                    • <bdo id='qyO1j'></bdo><ul id='qyO1j'></ul>
                    <tfoot id='qyO1j'></tfoot>
                  1. <legend id='qyO1j'><style id='qyO1j'><dir id='qyO1j'><q id='qyO1j'></q></dir></style></legend>

                  2. <small id='qyO1j'></small><noframes id='qyO1j'>

                    <i id='qyO1j'><tr id='qyO1j'><dt id='qyO1j'><q id='qyO1j'><span id='qyO1j'><b id='qyO1j'><form id='qyO1j'><ins id='qyO1j'></ins><ul id='qyO1j'></ul><sub id='qyO1j'></sub></form><legend id='qyO1j'></legend><bdo id='qyO1j'><pre id='qyO1j'><center id='qyO1j'></center></pre></bdo></b><th id='qyO1j'></th></span></q></dt></tr></i><div id='qyO1j'><tfoot id='qyO1j'></tfoot><dl id='qyO1j'><fieldset id='qyO1j'></fieldset></dl></div>