在代码下面打开webview。
func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let requestURL = URL(string: targetURL)
var req = URLRequest(url: requestURL!)
req.cachePolicy = NSURLRequest.CachePolicy.returnCacheDataElseLoad
req.allHTTPHeaderFields = [
"DEVICE-TYPE": "IOS"
];
wkWebView.load(req)
}
检查下面的http标头,但有时deviceType为空。
/**
* Decides whether to allow or cancel a navigation.
*/
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
let deviceType = navigationAction.request.value(forHTTPHeaderField: "DEVICE-TYPE")
if deviceType?.isEmpty ?? true { // <- Sometimes deviceType is empty, but not always.
//
}
decisionHandler(.allow)
}
无论特定的操作系统和iPhone版本如何,它都会发生。
是WKWebView的错误吗?
请帮帮我。
迅捷的版本是4.0。