我正在努力将UIWebView迁移到WKWebView。我已经更改了所有Delegate方法。我需要WKWebView委托方法等于下面的UIWebView委托方法。
我在UIWebView中写了下面的方法。帮我将下面的代码更改为WKWebView
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
guard let url = request.url else {
return true
}
guard !url.absoluteString.contains("data:application/pdf") else {
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action,
target: self,
action: #selector(share(sender:)))
return true
}
guard url.pathExtension != "pdf" else {
let safariVC = SFSafariViewController(url: url)
safariVC.modalPresentationStyle = .popover
present(safariVC, animated: true, completion: nil)
return false
}
guard url.isLogin() == false else {
AppDelegate.navigationController.signOut(.sessionOnly)
return false
}
guard let mobileSite = url.asMobileSite() else {
return true
}
let mobileRedirect = URLRequest(url: mobileSite)
webView.loadRequest(mobileRedirect)
return false
}