Я хочу попробовать флаг hasOnlySecureContent , и у меня есть этот код:
import UIKit
import WebKit
class ViewController: UIViewController, UITextFieldDelegate, WKUIDelegate, WKNavigationDelegate {
@IBOutlet weak var text: UITextField!
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView = WKWebView(frame: CGRect(x: 50, y: 330, width: self.view.frame.size.width, height: self.view.frame.size.height))
webView.navigationDelegate = self
}
@IBAction func loadMixedContentPage(_ sender: Any) {
// URL with mixed content
let mixedContentURL = URL(string: "https://www.google.com")
webView?.load(URLRequest(url: mixedContentURL!))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
// Detecting mixed content
if !(webView.hasOnlySecureContent) {
let alert = UIAlertController(title: "Security error", message: "Mixed content detected!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true)
} else {
let alert = UIAlertController(title: "Information", message: "Content is not mixed!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true)
}
}
Однако делегат didFinish никогда не вызывается при нажатии на метод loadMixedContentPage который использует метод load .Однако, если я использую loadHtml вместо загрузки, то вызывается делегат.
Есть ли у вас какие-либо предложения?