iOS 12 wkwebview无法使用重定向吗?

Mit*_*vis 6 xcode nginx swift wkwebview ios12

我有一个基本的webview,它加载了一个由nginx反向代理前面的网站,该代理将其转发到另一个站点。我可以在设备和仿真器(以及计算机)上使用safari,chrome firefox等加载它,但是当我尝试在wkwebview中加载它时,它会闪烁几次,然后进入白屏。 请注意,该应用程序在iOS 10-11中运行良好,但现在在iOS 12中无法使用。以下是一个简单的代码摘录,显示了我在做什么:

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

var webView: WKWebView!

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self
    view = webView
}

override func viewDidLoad() {
    super.viewDidLoad()

    let myURL = URL(string:"https://test.com")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)

我尝试将以下内容添加到我的Info.plist中,该方法也无效:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>test.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubDomains</key>
            <true/>
        </dict>
Run Code Online (Sandbox Code Playgroud)

它还在xcode的日志中显示了这一点:

[BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2] . 
[0x7f82f8d0efc0] get output frames failed, state 8196
Run Code Online (Sandbox Code Playgroud)

当我尝试使用Safari Dev Tools调试它时,它表明它正在尝试加载about:blank,这很奇怪,因为它再次适用于所有其他浏览器。在nginx端,我正在做的只是一个简单的proxy_pass规则,当我在应用程序中命中端点时,我可以在nginx访问日志中看到它以200响应。有人有任何想法吗?

Pab*_*nco 4

我遇到了同样的问题,我通过 WKNavigationDelegate 这样解决了它:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    if navigationAction.navigationType == .linkActivated {
        guard let url = navigationAction.request.url else {return}
        webView.load(URLRequest(url: url))
    }
    decisionHandler(.allow)
}
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你