我已经为Cocoa Touch Framework创建了示例应用程序,并且已经通过带有示例URL的WKWebView . 我在其中一个应用程序中使用了该框架,并尝试从主类中打开wkwebview . 下面是我的可可触摸框架代码 . 它始终显示我无法发出信号服务com.apple.WebKit.Networking:113:无法在控制台中找到此消息的指定服务 .
import UIKit
import WebKit
public class ConnectedAppController: UIViewController, WKNavigationDelegate {
var webView : WKWebView!
override public func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
public func opensampleWebView() {
let myBlog = "https://www.google.com/"
let url = NSURL(string: myBlog)
let request = URLRequest(url: url! as URL)
// init and load request in webview.
webView = WKWebView(frame: self.view.frame)
webView.navigationDelegate = self
self.view.addSubview(webView)
webView.load(request)
}
private func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
print(error.localizedDescription)
}
public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Strat to load")
}
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("finish to load")
}
2 回答
它's not obvious from your question, but I suspect you'从另一个类的
prepareForSegue
调用中调用opensampleWebView
.虽然您在
webView.load(request)
之前正确地调用self.view.addSubview(webView)
,但我怀疑您已经加载了're attempting to add to hasn' .如果你在
viewDidLoad
中调用opensampleWebView()
有什么区别吗?你需要覆盖函数 loadView()
Swift 4