我的课:
import UIKit
import WebKit
import PKHUD
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
webView.navigationDelegate = self
webView.load(URLRequest(url: URL(string: "https://www.google.com.br")!))
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
PKHUD.sharedHUD.contentView = PKHUDProgressView()
PKHUD.sharedHUD.show()
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
PKHUD.sharedHUD.contentView = PKHUDProgressView()
PKHUD.sharedHUD.hide()
}
}
但是只有“ http”的网站不起作用。那可能吗? 眼镜: 操作系统:11.4 斯威夫特语言 Xcode 9.4.1
答案 0 :(得分:1)
答案 1 :(得分:1)
之所以发生这种情况,是因为传输安全性阻止了不安全的HTTP连接。要允许HTTP,请打开Info.plist作为源代码并添加以下内容。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>yourDomain.com</key> // here put your domain or ip addres
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
答案 2 :(得分:0)
是的,但是为此您需要添加info.plist
NSAppTransportSecurity <-类型字典
NSAllowsArbitraryLoads <-类型布尔值是